PDA

View Full Version : args.length


kentyler
04-15-2003, 06:24 AM
When I try this function:
<canvas debug="true">
<script>
<![CDATA[
// write a word to the debugger
//
function check(args){
var actual = args.length;
var expected = args.callee.length;
if (actual != expected) {
debug.write("Wrong number of arguments: expected: " +
expected + "; actually passed " + actual);

}

}
// A function that demonstrates how to use the function above
function f(x,y,z) {
check(arguments);
return x + y + z;

}
debug.write ( f(2,3,4) );
]]>
</script>
</canvas>

I get
"reference to undefined property 'length'
Wrong number of arguments: expected: ; actually passed 3
9"
in the debugger. So it looks like args.callee.length is working but args.length is not.

Is this the intended behavior ?

hqm
04-15-2003, 06:59 AM
I think you should call "arguments.length", not "args.length". 'args' is your local name for an arg to the function, but "arguments" is the Javascript
special name for the array of arguments to the function.

You can see an example of the usage in WEB-INF/lps/components/debugger/debugger.lzx in the "write" method.

kentyler
04-15-2003, 07:40 AM
using arguments.length still throws
undefined object does not have a property 'length'
in the debug window.
I see in the example that " // Under some conditions (probably Flash 6), `arguments` works. // Under others (probably Flash 5), the following is necessary."
so perhaps the machine I'm trying this on doesn't have the Flash 6 plugin.

antun
04-15-2003, 10:05 AM
Hey kentyler

arguments is indeed an array local to a function that represents the arguments it is passed. It's an object too, and arguments.callee is a reference to the method itself.

However I don't understand what you're trying to do with this line:


var expected = arguments.callee.length;


(Note I changed args to arguments). It looks like you're asking for the length of the function.

-Antun

kentyler
04-16-2003, 05:54 AM
Antun,
The way I understood it, that line was trying to determine how many arguments where passed to the function. You can look here, for the full code.


http://www.seedwiki.com/page.cfm?doc=Arguments.Length&wikiid=1944

I am going through and testing all the core javascript functionality, since the docs don't specify exactly what does and what does not work in laszlo.

antun
04-16-2003, 07:23 AM
Hey Kentyler

I don't know if that's going to work, because effectively you're asking for the "length" of the function.

arguments.callee is a pointer to the function itself.

So arguments.callee.length is the lenght of the function, which is an undefined property.

-Antun

ows
04-18-2003, 07:35 PM
arguments.length should work, as per section 10.1.8 of the ECMAScript Edition 3 reference (at http://www.mozilla.org/js/language/). It's a bug (that we may not be able to fix) that it doesn't in all circumstances; we should quantify under what circumstances it fails.

kentyler
04-19-2003, 05:20 AM
the code here
http://www.seedwiki.com/page.cfm?doc=Arguments.Length&wikiid=1944
which is using args.length, doesn't work for arguments.length either, if that helps figure out when and where it doesn't work.