摘要: 很长一段时间认为, 构造函数显式的返回值是无效的, 最终都会返回this。 今天才发现其实是错误的。当构造函数中没有return语句时, 会默认返回this, 但是也可以返回任意的对象, 如果返回值不是对象, 仍然返回this。 不过这样也有后遗症, 实例将不会继承构造函数原型上的任何属性。例1: function Test() { this.name = "this's name"; var that = {}; that.name = "that's name"; return 10; } var test1 = new Test() 阅读全文
posted @ 2013-08-26 14:59 木头小木头 阅读(457) 评论(0) 推荐(0) 编辑