- <script>
- function Rectangle(w,h)
- {
- this.width=w;
- this.height=h;
- this.area=function(){return this.width*this.height+1;}
- }
- Rectangle.prototype.area=function(){return this.width*this.height+2;}
- var test=new Rectangle(5,10);
- test.area=function(){return this.width*this.height;}
- alert(test.area())
- alert(test.constructor.constructor)
- alert(test.constructor)
- alert(test.constructor.constructor)
- alert(test.constructor.prototype)
- alert(Rectangle.constructor.prototype)
- </script>
在js中的类,只写构造function
对象test.area()首先中调用自已对象的area()方法,
然后在自已的类中找
如果没有则在类的static属性prototype中找
2.第个类都可以当作方法直接调用
function Rectangle(w,h)
{
this.width=w;
this.height=h;
this.area=function(){return this.width*this.height+1;};
alert(111)
}
Rectangle(5,10);
3.
this.area是一般预定义是用
prototype定义了变量后,用于附加到类上