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

原型的一些知识

时间:2017-01-31 22:43:15      阅读:230      评论:0      收藏:0      [点我收藏+]

标签:作用域   return语句   语句   highlight   div   作用   prot   efi   turn   

普通调用函数,若函数没有return语句,等于return undefined,

构造函数调用的时候,1创建一个新对象,2将构造函数的作用域赋给新对象(this赋给了这个新对象),3执行构造函数中的代码(为这个新对象添加属性),4返回新对象


function A(){
//1这一步是看不到的,创建一个新对象;
var a = {};
//2第二步赋给新对象。
this = a;
//3执行
alert(this);
//4返回新对象
return this;
}
A.prototype.a = 1;
console.log(new A().a);
function A() {

    alert(this);






    return {a: ‘a‘};
}
A.prototype.a = 1;
console.log(new A().a);
new A()与原型没关系,因为返回的不是this,是自己返回的对象的属性a;

,

  

 

原型的一些知识

标签:作用域   return语句   语句   highlight   div   作用   prot   efi   turn   

原文地址:http://www.cnblogs.com/shenq/p/6359215.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!