Home > Web Front-end > JS Tutorial > body text

Javascript constructor example analysis_javascript skills

WBOY
Release: 2016-05-16 18:58:10
Original
1082 people have browsed it

/*
*(REFER TO P151)
*@time 2008-11-25
*/

Copy code The code is as follows:

//No return value
function Test0(){
this.name='test0';
}
var test0=new Test0;
//debugger;
alert(test0);//output [Object]
alert(test0.name);//output test0
//return one character String object
function Test(){
this.name='test';
return new String('123');// Return string object
}
var test=new Test();
alert(test);//Output 123
alert(test.name);//Output undefined, indicating that the object created by the constructor is a string object
//return a primitive Type string
function Test2(){
this.name='test2';
return '123';// Return string object
}
var test2=new Test2() ;
alert(test2);//Output [Object]
alert(test2.name);//Output test0
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!