(I) execute the function immediately
⑴ definitions: End the function definition, be called immediately, such a function is called immediately execute the function
⑵ Syntax: function Object ()
⑶ Note: the immediate execution of the function is often only once
⑷ Example 1:
(function(){
Alert ( " I'm an anonymous function " );
})();
⑸ Example 2:
(function(a,b){
console.log("a = "+a);
console.log("ab= "+b);
})(123,456);
(Ii) method of the object
⑴ function attribute may also be referred object
⑵ property holds if a function as an object of
⑶ we call this function is the object method
⑷ said, calling this function call the object's method (method)
⑸ but it is only the difference between the name , there is no other difference
Specific examples illustrate ⑹:
// Create a function
var obj = new Object();
// add to an object attribute
obj.name = " Monkey " ;
obj.age = 18 is ;
// the attribute value of the object may be any type of data, it may be functions
obj.sayName = function () {
console.log(obj.name);
};
function fun(){
console.log(obj.name);
};
// the console.log (sayName);
// modulation method
obj.sayName ();
// called function
Fun ();
(Iii) the enumeration object attributes
⑴ use for... In the statement
⑵ Syntax: for (var variables in the object) {
Statements...
}
⑶for .in statements: the object has several attributes, the loop will be performed several times,
Each execution, will be the object of a name attribute assignment to a variable
⑷ specific examples:
There obj = {
name:"孙悟空",
age:18,
gender:"男",
address:"花果山"
};
for(var n in obj){
console.log("属性名:"+n);
console.log("属性值:"+obj[n]);
}
⑸在控制台的示例演示结果: