1.javascript中函数有两种定义方式:
函数语句定义和表达式定义
//函数有定义 function test(){ console.log("This is a function"); } //表达式定义 var f = function(a){ return Math.sqrt(a); };
2.函数调用方式有以下四种:
1)作为函数
2)作为方法
3)作为构造函数
4)通过它们的call()和apply()方法间接调用
3.关键词this没有作用域的限制,不是变量,也不是属性名,是一个关键字。
如果嵌套函数作为方法调用,其this的值指向调用它的对象;如果嵌套函数作为函数调用,其this值不是全局变量(非严格模式下)就是undefined(严格模式下)。
var o = { m: function(){ var self = this; console.log(this); //this代表o f(); function f(){ console.log(this); //this代表全局对象或者undefined console.log(self); //self代表o } } }
原文:http://www.cnblogs.com/zjtTT/p/5022609.html