What is wrong with the arr.slice(x, y) in IE6?

F

F. Da Costa

Hi,

I was wondering whether someone could enlighten me as to the reason why the
slice does not work in IE when the arr is passed in properly.
Checked the values in the srcArr and they are correct so no problems there.
Gecko works as expected.
Prior to entering the function I can slice the array being entered so I
wouldn't expect an "Unexpected call to method or property access" (in IE 6).

I guess its something silly but as of yet i'm not seeing it.
Any suggestions would be appreciated.

TIA
Fermin DCG

===================================
function insertIntoArray(srcArr, insLoc, repl, insObj) {
alert(srcArr.slice(0,2));
var top = (repl) ? srcArr.slice(0, insLoc) : srcArr.slice(0, insLoc1);
var end = (repl) ? srcArr.slice(insLoc+1) srcArr.slice(insLoc+1);
return top.concat(insObj, end);
}
 
L

Lasse Reichstein Nielsen

F. Da Costa said:
I was wondering whether someone could enlighten me as to the reason
why the slice does not work in IE when the arr is passed in properly.

It works for me. Need more detail.
Checked the values in the srcArr and they are correct so no problems there.

What is the correct value?
Gecko works as expected.

What is the expected result?
Prior to entering the function I can slice the array being entered so
I wouldn't expect an "Unexpected call to method or property access"
(in IE 6).

Ok. Do you slice it?
I guess its something silly but as of yet i'm not seeing it.
Any suggestions would be appreciated.

function insertIntoArray(srcArr, insLoc, repl, insObj) {
alert(srcArr.slice(0,2));
var top = (repl) ? srcArr.slice(0, insLoc) : srcArr.slice(0, insLoc1);

Undefined variable "insLoc1", should be "insLoc" or "insLoc+1"? If
"insLoc", the branches are equal. If "insLoc+1", the insObj is
inserted *after* the insLoc'th element.
var end = (repl) ? srcArr.slice(insLoc+1) srcArr.slice(insLoc+1);
^ missing ":"

The branches are equal, so no need for conditional expression.
return top.concat(insObj, end);
}

The code is syntactically incorrect. Please post the actual code that
fails, and say what you do (the actual values of the arguments that
fail), what you expect to happen (the final result, or even the vlaues
of top and end), and what actually happens.

Then I'm sure we will be able to help you. Until we have that information,
all we can do is guess (and while it sometimes seems that way, we are not
oracles :)

/L
 
F

F. Da Costa

Lasse said:
The code is syntactically incorrect. Please post the actual code that
fails, and say what you do (the actual values of the arguments that
fail), what you expect to happen (the final result, or even the vlaues
of top and end), and what actually happens.
I understand, so i'll first present the html code from where the call is
made followed by the js code used.
Note:
Working env contains two frames. 1 for scripts (like a library with
accessible variables) & the other for showing content.
Clicking on a link gets one into the page as shown below.

Verified:
The existence (with contents) of *top.frmScripts._skeleton*.
The creation and fill of *arr*.
IE immediately jumps to the last render <script> whilst Gecko goes in and
comes back with an extended *top.frmScripts._skeleton* (which is what i
intended for it to do).
Entering the function goes as planned & all the variables are filled as
expected. Also did an alert() check in IE.
The monment it hits the slice statement it falls over on the first slice
request. So it does *not* slice in the alert.

My feeling (for what its worth):
It is almost as if there is something of a type change. From Array to
something that does *not* support the slice method (judging by the error
reported, Unexpected call to method or property access).

I hope this is complete enough to help me underatand what i'm doing wrong.


=== .html ===
<body>
<div id="doc">
<h3>This is the MAIN div</h3>
<script>
var arr = new Array();
arr.push('<tbody id="ognl:scriptParameter">');
arr.push('<tr><td >row-0 -:- col-0</td><td>row-0 -:-
col-1</td></tr><tr><td>row-1 -:- col-0</td><td>row-1 -:-
col-1</td></tr><tr><td>row-2 -:- col-0</td><td>row-2 -:- col-1</td></tr>');
arr.push('</tbody>');

top.frmScripts._skeleton = insertIntoArray(top.frmScripts._skeleton,
top.frmScripts.getTbodyIndexById(top.frmScripts._skeleton, 'tb1'), true, arr);
var skeleton = top.frmScripts._skeleton;
</script> Just processed tb1

<script>
var skeleton = top.frmScripts._skeleton;
alert("Main::pre render skel.len: "+skeleton.length);
for (var i=0, len=skeleton.length; i<len; i++)
document.write(skeleton);
skeleton = null;
</script>
</div>
</body>

=== CreateTbody.js === can be found in the frame called frmScripts
function getTbodyIndexById(tableSkeleton, tbodyID) {
for (var i=0, len=tableSkeleton["length"]; i<len; i++) {
if (tableSkeleton.indexOf(tbodyID)>1) return i;
}
return 0;
}

/**
* This function can be used to insert an element or another array into an
array.
* @param sourceArray = the array into which one wants to do the insertion
* @param insertLocation = the location (int) where the insertion needs to
take place
* @param replace = boolean indicating what should happen to the element
on insertLocation
* @param insertObject = the object (string || array) to be inserted
*
* @return the array with the inserted data
*/
function insertIntoArray(sourceArray, insertLocation, replace, insertObject) {
alert("insert:: slice test = "+tmp.slice(0,2));
var top = (replace) ? sourceArray.slice(0, insertLocation) :
sourceArray.slice(0, insertLocation+1);
var end = (replace) ? sourceArray.slice(insertLocation+1) :
sourceArray.slice(insertLocation+1);
return top.concat(insertObject, end);
}


all we can do is guess (and while it sometimes seems that way, we are not
oracles :)
If not that then definitely 'see-ers' ;)

TIA
Fermin DCG
 
F

F. Da Costa

Lasse said:
It works for me. Need more detail.
Has cost me a whole Sunday trying to figure it out.
Still not resolved but I found an Array extension (prototypes) to include
missing function to IE and that *did* make it work.

I attached the file I found on the web that resolved the whole thing
(obviously you won't benefit but others might ;))

I would like to thank you however for the effort you made to react back.

Cheers,
Fermin DCG
 
T

Thomas 'PointedEars' Lahn

F. Da Costa said:
I attached the file I found on the web that resolved the whole thing
(obviously you won't benefit but others might ;))

Please never ever do this again. Attachments in a non-binary group like
this are a Bad Thing. People subscribe to non-binary groups because
they want text content and *small* messages only. Besides, a .js file,
when displayed inline -- and yours should be:

| --------------040106080409010602080206
| Content-Type: application/x-javascript;
| name="ArrayExtension.js"
| Content-Transfer-Encoding: 8bit
| Content-Disposition: inline;
| filename="ArrayExtension.js"

--, could be easily executed. Hopefully nobody has scripting enabled
for his/her newsreader app, otherwise viruses/worms could be easily
distributed, since many people use a e-mail/news client combo. Or they
get a script error due to a restricted DOM or bad syntax, unwished as well.

Post a URI for the file instead, most newsreaders will make it a
hyperlink. Or tell people to send you mail if they want the source
code (another reason why one should post with a valid e-mail address).
Or post it as plain text if it does not exceed, say, 100 lines.

Thanks.


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top