js中的prototype与constructor
来源:互联网 发布:java 线程同步卖票 编辑:程序博客网 时间:2024/05/16 05:38
- <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定义了变量后,用于附加到类上
- js中的prototype与constructor
- js中的constructor与prototype
- 关于JS中的constructor与prototype
- 关于JS中的constructor与prototype
- 关于JS中的constructor与prototype
- 关于JS中的constructor与prototype .
- 关于JS中的constructor与prototype
- 关于JS中的constructor与prototype
- JS中的constructor与prototype(1)
- 关于JS中的constructor与prototype
- 关于JS中的constructor与prototype【转】
- 关于JS中的constructor与prototype
- JS中的constructor与prototype【转】
- 关于JS中的constructor与prototype
- 关于JS中的constructor与prototype
- 关于JS中的constructor与prototype
- 关于JS中的constructor与prototype
- 关于JS中的constructor与prototype
- Liferay 中的javascript
- Hibernate主键类型详解
- 《Getting Real》快速读书笔记
- dsf
- 动态网页,设置多个上传文件,innerHTML的妙用 类似的例子
- js中的prototype与constructor
- display aspect ratio和遥控器上的调整
- ubuntu ftp server配置
- pdf文件中ASCII85的解码程序
- NAT与NAPT
- 按sun标准解析的java class文件
- ${}el表达式切割字符串
- 《COM本质论》笔记——引子
- 最好的五个文本编辑器