Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript create function

What is the difference between this:

var doSomething=function()
{
    //do blah blah blah...  
}

And this:

function doSomething()
{
    //do blah blah blah...  
}

Another question: In PHP, we create a function by doing this:

function doSomething(a,b)
{
    //do something to variable a and b...
}

In JavaScript, we may have an object before the function:

object.doSomething(a);

My second question is, how would you create a function which requires an object in JavaScript?

like image 815
theHack Avatar asked Sep 11 '26 23:09

theHack


1 Answers

The number one Google result for "function statement vs expression javascript" is another Stack Overflow question:

What is the difference between a function expression vs declaration in JavaScript?

It references the following article, which is the definitive reference on the subject:

http://kangax.github.com/nfe/

like image 148
Wayne Avatar answered Sep 14 '26 13:09

Wayne



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!