js中构造函数使用new创建对象时,this与新建对象关系是怎样的?
JavaScript高级程序设计(第3版)P144
其中(2)所表达的意思。与我的理解有所出入。
-------------------------------引用高程内容 start---------------------------------------

英文解释
To create a new instance of Person, use the new operator. Calling a constructor in this manner
essentially causes the following four steps to be taken:
Create a new object.
Assign the this value of the constructor to the new object (so this points to the new object).
PS:(将构造函数的this的值赋给新的对象)
Execute the code inside the constructor (adds properties to the new object).
Return the new object.
------------------------------引用高程内容 end--------------------------------------
关于使用new关键字调用构造函数的步骤,以下是我的理解。
(1).var newobj = {}; //首先创建一个新的临时对象
(2).newobj.call(newobj ); //在新对象的作用域中执行构造函数。
也就是将newobj赋给this。而书上说的正相反。“将构造函数的this的值赋给新的对象”。如何理解这句话?
其中(2)所表达的意思。与我的理解有所出入。
-------------------------------引用高程内容 start---------------------------------------

英文解释
To create a new instance of Person, use the new operator. Calling a constructor in this manner
essentially causes the following four steps to be taken:
Create a new object.
Assign the this value of the constructor to the new object (so this points to the new object).
PS:(将构造函数的this的值赋给新的对象)
Execute the code inside the constructor (adds properties to the new object).
Return the new object.
------------------------------引用高程内容 end--------------------------------------
关于使用new关键字调用构造函数的步骤,以下是我的理解。
(1).var newobj = {}; //首先创建一个新的临时对象
(2).newobj.call(newobj ); //在新对象的作用域中执行构造函数。
也就是将newobj赋给this。而书上说的正相反。“将构造函数的this的值赋给新的对象”。如何理解这句话?
...全文
相关推荐
Javascript 构造函数详解
Javascript构造函数是非常强大的,它可能也是Javascript能被充分利用的特点之一。但是如果你想真正的了解Javascript,你还是应该明白构造函数是如何工作的。本文,我们将从三个方面来讲述构造函数。
js构造函数创建对象是否加new问题
本篇文章主要给大家详细分析了js构造函数创建对象加new与不加new的问题,有这方面兴趣的参考学习下。
JS使用new操作符创建对象的方法分析
主要介绍了JS使用new操作符创建对象的方法,结合实例形式分析了javascript面向对象程序设计类的定义、new操作符对象的创建及相关操作注意事项,需要的朋友可以参考下
js中new一个对象的过程
本文主要介绍了js中new一个对象的过程。具有很好的参考价值,下面跟着小编一起来看下吧
javascript中使用new与不使用实例化对象的区别
主要介绍了javascript中使用new与不使用实例化对象的区别的相关资料,需要的朋友可以参考下


