js中的继承与重写
来源:互联网 发布:庄子说小知不及大知 编辑:程序博客网 时间:2024/05/16 16:13
rt.
用function 分别定义Person和Account类模型,其中Account从Person继承,并重写toString()方法
<script type="text/javascript">function go() {var acc1 = new Account('Taro', 'Shibuya1-1-2', '1001', 20000);var acc2 = new Account('Hanako', 'Akasaka2-3-4', '1002', 35000);acc1.toString();acc2.toString();}// 定义Person构造器function Person(name, address) {this.name = name;this.address = address;}// 在Person.property中添加toString方法Person.prototype.toString = function() {document.write(this.name + " " + this.address + "<br>");}// 定义Account构造器function Account(name, address, number, amount) {// 从Person继承this.newObj = Person;this.newObj(name, address);delete this.newObj;// Account特有属性this.number = number;this.amount = amount;}Account.prototype = Object.create(Person.prototype);// 设置"constructor" 属性指向AccountAccount.prototype.constructor = Account;// 更改Person中toString方法Account.prototype.toString = function() {document.write(this.name + " " + this.address+ " " + this.amount + "<br>");}Account.prototype.deposit = function(x) {this.amount += x;}Account.prototype.withdraw = function(x) {this.amount -= x;}</script>
0 0
- js中的继承与重写
- JS 继承与重写
- js继承中的方法重写
- Swift 中的继承 与 重写
- C#中的继承、隐藏与重写
- Java中的继承,重写与遮蔽
- js中的原型与继承
- 继承中的方法重写
- 继承中的方法重写
- 继承中的重写
- 继承与重写:
- 关于继承与重写
- 继承与重写
- 不能说的秘密-重载、重写与继承中的构造方法
- [转]js 重写继承方法
- JAVA中的继承和重写
- java 继承中的方法重写
- Java:关于继承中的重写
- WebView相关
- android 密码输入通过复选框实现明文密文显示
- 模仿微信摇一摇
- linux下文件的读写操作(openreadwrite)
- 一、SAE
- js中的继承与重写
- Windows 7上QTP11破解及java等插件破解方法
- -Dmaven.multiModuleProjectDirectory system propery is not set. Check $M2_HOME environment variable a
- 白书练习 TEX
- 电容滤波原理
- 单例模式
- 朋友圈红包照片,花钱看果照,技术不可耻谁看谁流氓?
- ajax--上传进度条
- dell E6420 ubuntu无线网卡驱动安装