博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
构造函数
阅读量:4666 次
发布时间:2019-06-09

本文共 584 字,大约阅读时间需要 1 分钟。

function C(amount){

this.balance=amount;
this.deposit=deposit;
this.withdraw=withdraw;
this.toString=toString;
}
function deposit(amount){
this.balance+=amount;
}
function withdraw(amount){
if(amount<=this.balance){
this.balance-=amount;
}
if(amount>this.balance){
alert("余额不足");
}
}
function toString(amount){
return "余额:"+this.balance;
}
var account=new C(500);
account.deposit(1000);
console.log(account.toString());

account.withdraw(750);

console.log(account.toString());

account.withdraw(375);

console.log(account.toString());

转载于:https://www.cnblogs.com/ArielChen/p/7263061.html

你可能感兴趣的文章
【转】zookeeper 学习资料
查看>>
11-3 多道批处理系统
查看>>
linux安装nginx
查看>>
Jwt在javaweb项目中的应用核心步骤解读
查看>>
[Vue] : Vue指令
查看>>
捆绑和缩小(BundleConfig.RegisterBundles) 第五章 : MVC中的使用 | {version}用法
查看>>
spring boot 使用 HandlerInterceptor
查看>>
[Delphi]接口认识
查看>>
oracle 安装
查看>>
ssh scp ssh-copy-id 非22端口的操作方法
查看>>
Spring MVC 的@RequestParam注解和request.getParameter("XXX")
查看>>
iOS 带IAP提交注意事项及无法submit for review的解决方案
查看>>
用js给元素加css
查看>>
Objective-C基础1:OC中类的继承和组合
查看>>
转载牛人的英语学习方法,值得学习
查看>>
iOS的开发工具介绍
查看>>
switch 语句来选择要执行的多个代码块之一。
查看>>
【Java】 剑指offer(30) 包含min函数的栈
查看>>
cer pfx格式数字证书区别
查看>>
2013.11.24 流水
查看>>