码迷,mamicode.com
首页 > 其他好文 > 详细

模仿new

时间:2016-01-11 21:40:55      阅读:164      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!