JS中的 new 操作符简单理解
来源:互联网 发布:淘宝点击率的计算公式 编辑:程序博客网 时间:2024/05/14 15:04
首先上一一个简单的 new 操作符实例
简单来说,上述例子中,以 new 操作符调用构造函数的时候,函数内部发生以下变化:
对于以上的讲述不知道有没有讲清楚。
相当于运行以下代码
对于ES5中添加了 Object.create(),
- var Person = function(name){
- this.name = name;
- this.say = function(){
- return "I am " + this.name;
- };
- }
- var nyf = new Person("nyf");
- nyf.say();
1、创建一个空对象,并且 this 变量引用该对象,同时还继承了该函数的原型。
2、属性和方法被加入到 this 引用的对象中。
3、新创建的对象由 this 所引用,并且最后隐式的返回 this 。
以上情况在 new 操作符调用下,后台就相当于
- var Person = function(name){
- //var this = {};
- this.name = name;
- this.say = function(){
- return "I am " + this.name;
- };
- //return this;
- }
- var obj = new Base();
- var obj = {};
- obj.__proto__ = Base.prototype;
- Base.call(obj);
- if(typeof Object.create !== "function"){
- Object.create = function(o){
- function F(){};
- F.prototype = o;
- return new F();
- }
- }
0 0
- JS中的new操作符简单理解
- JS中的 new 操作符简单理解
- JS中的 new 操作符简单理解
- 理解js中的new操作符。
- 理解js中的new
- 理解js中的new
- 对js操作符new的理解
- 深入理解C++中的new操作符
- js中的的new操作
- js new操作符
- [JS] new操作符
- JS new 操作符
- js--new操作符
- js new操作符
- 理解js中的new ——2
- JS 中 new 操作符
- JS 中 new 操作符
- JS 中 new 操作符
- Spring的属性依赖检查
- Matlab函数练习
- 作业调度器
- JavaScript中的this
- Reverse Linked List
- JS中的 new 操作符简单理解
- 通过FTP Server加载VxWorks映像
- 设计模式之工厂方法模式
- 一个人的成功取决于晚上的8点至10点
- Python IOError: File not open for writing
- 01背包java 源码
- git 上初始化一个代码库并且成为共享库
- mysql 索引
- Android开发者指南-Action Bar