首页 > 其他 > 详细

模仿new

时间:2016-01-11 21:40:37      阅读:229      评论:0      收藏:0      [点我收藏+]
 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");//函数表达式后面可以直接调用函数的方法,但是函数声明不行。

 

模仿new

原文:http://www.cnblogs.com/callmegongchenglion/p/5122496.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!