Показать сообщение отдельно
  #3 (permalink)  
Старый 18.04.2015, 03:02
Кандидат Javascript-наук
Посмотреть профиль Найти все сообщения от theKingOfJava
 
Регистрация: 31.03.2015
Сообщений: 113

Сообщение от alex.vv
и где реализация?
Все ждал, что кто нибудь проснется.

Ладно, вот простейшая реализация:
Account={
 balance: 0,
 create: function(){return Object.create(this)},
 withdraw: function(amount){if((this.balance-amount)<0) return console.log("out of limit!"); this.balance-=amount},
 deposit: function(amount){this.balance+=amount},
 check: function(){console.log(this.balance)}
}

////////example//////////////////

account=Account.create()
with(account){
 deposit(100)  
 check()       //>>>> 100
 withdraw(50)  
 check()       //>>>> 50
 withdraw(70)  //>>>> out of limit!
 check()       //>>>> 50
}
Ответить с цитированием