随笔分类 - javascript进阶
摘要:1.当function里嵌套function时,内部的function可以访问外部function里的变量。 2. 外部变量(环境变量?), 包括: 2.1 全局变量,包括DOM。 2.2 外部函数的变量或函数。 如果一个函数访问了它的外部变量,那么它就是一个闭包。 从技术上来讲,在JS中,每个fu
阅读全文
摘要://对象冒充实现继承 function Person() { this.speak = function () { alert("我是人类"); }; } function Chinese() { Person.call(this); } var p = new Chines...
阅读全文
摘要:function Person() { } Person.prototype.dance = function () { } function Ninjia() { } Ninjia.prototype = new Person(); var ninjia = new Ninjia();
阅读全文
摘要:点我 var button={ clicked:false, click:function(){ debugger; this.clicked=true; console.assert(!(button.clicked),"The button has been clicked"); } } var elem...
阅读全文
摘要:function addMethod(object,name,fn){ var old=object[name]; object[name]=function(){ if(fn.length==arguments.length) return fn.apply(this,arguments); else if(typeo...
阅读全文