<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type=text/javascript charset=utf-8>
function F(){
this.name = 1;
this.sc = 4;
alert(2);
return function(){
this.age = 2;
this.name = 3;
alert(1);
}
}
var f = new F();
alert(typeof f);//function
alert(f.name);//輸出函數的名字
alert(f.age);//undefined
alert(f.sc);//undefined
function G(){
this.name = 1;
this.sc = 4;
return {
name : 14,
age : 15
};
}
var g =new G();
alert(typeof g);//object
alert(g.name);//14
alert(g.age);//15
alert(g.sc);//undefined
function H(){
this.name = 1;
this.sc = 4;
}
var g =new H();
alert(typeof g);//object
alert(g.name);//1
function H(){
this.name = 1;
this.sc = 4;
return this;
}
var g =new H();
alert(typeof g);//object
alert(g.name);//1
alert(g.sc);//4
function L(){
this.name = 1;
this.sc = 4;
return new Array(1,2,3);
}
var l =new L();
alert(typeof l);//object
alert(l);//1,2,3
alert(l.name);//undefined
alert(l.sc);//undefined
function E(){
this.name = 1;
this.sc = 4;
return 'ssss';//return的是引用類型new函數就傳回return的引用類型對象,基本類型就還是傳回函數類的執行個體對象。
}
var e =new E();
alert(typeof e);//object
alert(e);//object
alert(e.charAt(1));//e.charAt is not a function
alert(e.name);//1
alert(e.sc);//4
</script>
</head>
<body>
</body>
</html>
function F(){
this.n = 1;
this.sc = 4;
return function FF(){
this.n = 11;
this.sc = 44;
return function FFF(){
this.n = 111;
this.sc = 442;
}
}
}
var f = new F();
alert(typeof f);
alert(f.name);//FF, new F(),函數F值執行他的那層執行一遍
alert(f.n)//undefined
function F(a){
this.n = 1;
this.sc = 4;
return new init(a); //new init(),如果init類沒有return引用就傳回init類的對象,否則傳回init類中return的引用對象
}
function init(){
this.n = 11;
return {n:arguments[0]}
}
var d = F(3);
alert(d.n);//3
function F(a){
this.n = 1;
this.sc = 4;
return new init(a);
}
function init(){
this.n = 11;
return 44
}
var d = F(3);
alert(d.n);//11
function F(a){
this.n = 1;
this.sc = 4;
return new G(a); //不一定傳回G對象,傳回{}
}
function G(){
this.n = 11;
return {n:arguments[0]}
}
var d =new F(3); //不一定傳回F的對象,傳回的是F函數裡面的new G()這個G的對象
alert(d.n);//3