标签:
1 Function.prototype.method = function (name, func) { 2 this.prototype[name] = func; 3 }; 4 Function.method("createInstance", function () { 5 console.log("I was invoked!"); 6 var that = Object.create(this.prototype); 7 var other = this.apply(that, arguments); 8 return (typeof other === "object" && other) || that; 9 }); 10 var Person = function (name) { 11 this.name = name; 12 }.createInstance("Jack");//函数表达式后面可以直接调用函数的方法,但是函数声明不行。
标签:
原文地址:http://www.cnblogs.com/callmegongchenglion/p/5122496.html