<html>
<head>
<title></title>
<script type="text/javascript">
var x={
name:"hello",
y=function (){
this.name="mabt";
this.name1="mabt1";
this.age="30";
this.say=function (){
document.write(this.name+"--"+this.age+"岁<br/>");
document.write(this.name1+"--"+this.age+"岁<br/>");
}
};
y.apply(y);
y2=new y;
alert(y2.name);
alert(y2.name1);
y2.say();
alert(typeof y);//function
alert(typeof y2);//object
</script>
</head>
<body>
<div id="content"></div>
</body>
</html>
<head>
<title></title>
<script type="text/javascript">
var x={
name:"hello",
say:function(){ document.write(this.name+"--"+this.age+"岁<br/>");}
}x.say();
//mabt--30岁
y=function (){
this.name="mabt";
this.name1="mabt1";
this.age="30";
this.say=function (){
document.write(this.name+"--"+this.age+"岁<br/>");
document.write(this.name1+"--"+this.age+"岁<br/>");
}
};
y.apply(y);
y.say();
//--30岁 //y指向一个匿名函数对象,因此其name属性无法修改。
y2=new y;
alert(y2.name);
alert(y2.name1);
y2.say();
alert(typeof y);//function
alert(typeof y2);//object
//mabt--30岁
//mabt1--30岁</script>
</head>
<body>
<div id="content"></div>
</body>
</html>