首页 > 其他 > 详细

函数表达式和构造函数的区别

时间:2016-05-30 23:16:02      阅读:331      评论:0      收藏:0      [点我收藏+]
var a=function(config){
this.name=config;
this.out = function(){
alert(1)
}

}
a.name=‘hewenk‘;
a.prototype.inner=function(){
alert(1)
}
var n=new a(‘1234‘);
n.out();//1
n.inner();//1
console.log(n.name)//1234
console.log(a.name);//空 函数表达式的自定义属性实例无法继承

function b(config){
this.name=config;
this.out = function(){
alert(2)
}
}
b.prototype.inner=function(){
alert(2);
}
b.name = ‘1234‘;
var m=new b(‘123‘);
m.out();//2
m.inner();//2
console.log(m.name);//123 构造函数的自定义属性实例无法继承

两没有区别在使用的过程中,都不能继承自定义的属性

函数表达式和构造函数的区别

原文:http://www.cnblogs.com/-youth/p/5544141.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!