/*
*(REFER TO <JAVASCRIPT CORE>P151)
*@time 2008-11-25
*/
实现代码如下:

//没有返回值
function Test0(){
this.name='test0';
}
var test0=new Test0;
//debugger;
alert(test0);//输出[Object]
alert(test0.name);//输出test0
//return 一个字符串对象
function Test(){
this.name='test';
return new String('123');// 返回字符串对象
}
var test=new Test();
alert(test);//输出123
alert(test.name);//输出undefined,说明有构造函数创建的对象是字符串对象
//return 一个原始类型字符串
function Test2(){
this.name='test2';
return '123';// 返回字符串对象
}
var test2=new Test2();
alert(test2);//输出[Object]
alert(test2.name);//输出test0

以上就是【Javascript 构造函数 实例分析】的全部内容了,欢迎留言评论进行交流!

赞(0) 踩(0)
发表我的评论

最新评论

  1. 暂无评论