The difference between var fun = function() {} and function fun() {} is that in the first case it is stored in the variable fun. To call the function, you have to call fun(). Having it in a variable lets you pass the function around.
You can create objects by using functions
function MyClass() {
this.fun = function() { alert('Hello world'); }
}
var obj = new MyClass();
obj.fun();
or JSON
var obj = {
fun: function() { alert('Hello world'); }
};
obj.fun();
You can further extend the objects or their prototypes with new functions.
Edit. Sorry for the wrong answer: one shouldn't try to do these kinds of things at 4 am.
The difference between var fun = function() {} and function fun() {} is that in the first case it is stored in the variable fun. To call the function, you have to call fun(). Having it in a variable lets you pass the function around.
You can create objects by using functions
function MyClass() {
this.fun = function() { alert('Hello world'); }
}
var obj = MyClass();
obj.fun();
or JSON
var obj = {
fun: function() { alert('Hello world'); }
};
obj.fun();
You can further extend the objects or their prototypes with new functions.
Edit. Sorry for the wrong answer: one shouldn't try to do these kinds of things at 4 am.
The difference between var fun = function() {} and function fun() {} is that in the first case it is stored in the variable fun. To call the function, you have to call fun(). Having it in a variable lets you pass the function around.
You can create objects by using functions
function MyClass() {
this.fun = function() { alert('Hello world'); }
}
var obj = new MyClass();
obj.fun();
or JSON
var obj = {
fun: function() { alert('Hello world'); }
};
obj.fun();
You can further extend the objects or their prototypes with new functions.
Edit. Sorry for the wrong answer: one shouldn't try to do these kinds of things at 4 am.
The difference between var fun = function() {} and function fun() {} is that in the first case the function is not executed immediately instead a reference to it is stored in the variable fun. To call the function, you have to call fun() at some later stage. Having it in a variable lets you pass the function around.
You can create objects by using functions
function MyClass() {
this.fun = function() { alert('Hello world'); }
}
var obj = MyClass();
obj.fun();
or JSON
var obj = {
fun: function() { alert('Hello world'); }
};
obj.fun();
You can further extend the objects or their prototypes with new functions.
Edit. Sorry for the wrong answer: one shouldn't try to do these kinds of things at 4 am.
The difference between var fun = function() {} and function fun() {} is that in the first case the function is not executed immediately instead a reference to it is stored in the variable fun. To call the function, you have to call fun() at some later stage.
You can create objects by using functions
function MyClass() {
this.fun = function() { alert('Hello world'); }
}
var obj = MyClass();
obj.fun();
or JSON
var obj = {
fun: function() { alert('Hello world'); }
};
obj.fun();
You can further extend the objects or their prototypes with new functions.
The difference between var fun = function() {} and function fun() {} is that in the first case it is stored in the variable fun. To call the function, you have to call fun(). Having it in a variable lets you pass the function around.
You can create objects by using functions
function MyClass() {
this.fun = function() { alert('Hello world'); }
}
var obj = MyClass();
obj.fun();
or JSON
var obj = {
fun: function() { alert('Hello world'); }
};
obj.fun();
You can further extend the objects or their prototypes with new functions.
Edit. Sorry for the wrong answer: one shouldn't try to do these kinds of things at 4 am.
The difference between var fun = function() {} and function fun() {} is that in the first case the function is not executed immediately instead a reference to it is stored in the variable fun. To call the function, you have to call fun() at some later stage.
You can create objects by using functions
function MyClass() {
this.fun = function() { alert('Hello world'); }
}
var obj = MyClass();
obj.fun();
or JSON
var obj = {
fun: function() { alert('Hello world'); }
};
obj.fun();
You can further extend the objects or their prototypes with new functions.