Function.prototype.method=function(name, func){ this.prototype[name]=func; // use prototype to add a function return this; } String.method("ping",function(content){ // add method to String var c=content; return function(){alert(this + content);} // use closure go get the variable }("kaqi")); //invoke method in definition "Hello ".ping()
<<javascript:the good part>> prototype, closure, module example
最新推荐文章于 2024-11-13 15:29:17 发布