Function type
Because it is an instance of function Function type, the function name is a pointer to a function object, not a function connected tightly together, which led to the js not really overloaded, but the advantage is, function objects can be an argument to a function or return value;
Instead of performing the function pointer to access a function object itself can not be bracketed
var func = new Function("x", "y", "return x + y");// 构造函数来实例化一个Function类型, 但不推荐使用
function func(x, y){
return x + y;
}// 函数声明 js引擎会将所有的函数声明提升到顶部
var func = function (x, y){ return x + y };// 函数表达式 变量的赋值, 变量func保存着 function(x, y){ return x + y} 这个对象
Function type, there are two special objects: arguments and this, in the former which has passed into the function of all parameters, there is a callee property, which is a pointer to the instance has this property Function; and the this pointer to the execution environment , which is an example of Global type. is a window in your browser.
function b(){
console.log(arguments.callee);
}
Function type properties and methods
length // Funciton实例期望接收形式参数的个数
prototype //
apply();// 非继承的方法
// apply(Function实例运行的作用域:this, Array实例或arguments)
call();// 非继承的方法
// call(Function实例运行的作用域:this, arg1, arg2, ...)
//
bind( X );// 将Function的实例的this指向 对象 X
In addition, Function There is also a special type of property: caller, this is a pointer, it can not be assigned to this property in strict mode.
Function Type Function One example of a type of a call to another instance b, then the caller attribute instance b will instance a point;
function a(){
b();
}
function b(){
console.log(arguments.callee.caller);
}