浅谈new操作符
来源:互联网 发布:python socket 运用 编辑:程序博客网 时间:2024/05/20 12:49
var Person = function(name){
this.name = name;
this.say = function(){
return "I am" + this.name;
}
}
var nyf = new Person("nyf");
/* nyf.say();
以new操作符调用构造函数的时候 发生以下变化
1.创建一个空对象,并且this变量引用该对象,同时还继承了该函数的原型。
2. 属性和方法被加入到this引用的对象中
3.新创建的对象由this所引用,并且最后隐式的返回this
以上情况在new操作符的调用下,后台就相当于
*/
var Person =function(name){
//var this = {} 创建this空对象
this.name = name; //属性加入到this对象中
this.say = function(){ //方法加入到this对象中
return "I am" + this.name;
};
//return this 隐式的返回this对象
}
this.name = name;
this.say = function(){
return "I am" + this.name;
}
}
var nyf = new Person("nyf");
/* nyf.say();
以new操作符调用构造函数的时候 发生以下变化
1.创建一个空对象,并且this变量引用该对象,同时还继承了该函数的原型。
2. 属性和方法被加入到this引用的对象中
3.新创建的对象由this所引用,并且最后隐式的返回this
以上情况在new操作符的调用下,后台就相当于
*/
var Person =function(name){
//var this = {} 创建this空对象
this.name = name; //属性加入到this对象中
this.say = function(){ //方法加入到this对象中
return "I am" + this.name;
};
//return this 隐式的返回this对象
}
0 0
- 浅谈new操作符
- placement new 操作符
- 操作符new
- 重载New操作符
- new操作符
- placement new 操作符
- new 操作符
- 布局NEW操作符
- 布局new操作符
- 重载new操作符
- c++ new操作符
- c#new操作符
- new delete操作符
- js new操作符
- placement new 操作符
- new/delete操作符
- [JS] new操作符
- placement new 操作符
- STM32使用扫描模式采集信号
- 图书馆看到的,很有道理,尤其是SWOT分析法,学国商的人都不陌生吧
- android edittext 输入密码可见
- thinkphp框架index.php文件中定义site_url的小技巧
- Objective-C 时间操作实用方法总结
- 浅谈new操作符
- C语言强化(七)链表相交问题_5 找到两个有环链表的相交结点
- 前端工程师应该具备的三种思维
- 配置cordova-android
- 提高JQuery性能
- mysql远程登陆和本地登陆的一些问题
- Samba CVE-2015-0240 远程代码执行漏洞利用实践
- NYOJ1032 【Save Princess】
- ubuntu12.04下建立eclipse的android开发环境相关问题