|
-
Junior Member
f = function() or function f ()
Hi- I've been away from flash for a while, and have just written a quick game, to test my skills...
One thing i have forgotten/missed:
What is the difference between these two:
code:
function f() {
// do somthing
}
code:
f=function() {
// do something
}
Hariyemadzisawira nhaka yedu! Down the SCUD and win!
I'm too lazy to read Private Messages.
-
AFAIK, there is almost no difference between them. The only difference that I notice about them is this:
You can only declare functions from other reference (timeline or object/array) using the latter form:
code: _global.myFn = function()
{
// codes
}
or
code: myObject.myFn = function()
{
// codes
}
and not
code: function myObject.myFn ()
{
// codes
}
Furthermore, the functions declared in the second form can be declared using var:
code:
var myFn = function()
{
// codes
}
Therefore, the second form is advantageous.
-
Junior Member
Yes, I wrote out about 200 lines of code in two sessions and noticed that I had used the two different syntaxes, yet everything was working.
I usually use the second, I recall.
Thanks!
Hariyemadzisawira nhaka yedu! Down the SCUD and win!
I'm too lazy to read Private Messages.
-
Senior Member
another difference, functions defined using
function functionName() {
}
can be called before the function declaration in your code, for example,
code:
sayHello();
function sayHello() {
trace("hello");
}
works, but
code:
sayHello();
sayHello = function() {
trace("hello");
};
doesn't.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|