We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
var Beverage = function(){}; Beverage.prototype.boilWater = function(){ console.log('boil water'); } Beverage.prototype.brew = function(){ console.log('brew Beverage'); } Beverage.prototype.pourInCup = function(){ console.log('pour in cup'); } Beverage.prototype.addCondiments = function(){ console.log('add condiments'); } Beverage.prototype.init = function(){ this.boilWater(); this.brew(); this.pourInCup(); this.addCondiments(); } // 泡咖啡 var Coffee = function(){}; Coffee.prototype = new Beverage(); Coffee.prototype.boilWater = function(){ console.log('boil water'); } Coffee.prototype.brew = function(){ console.log('brew coffee'); } Coffee.prototype.pourInCup = function(){ console.log('pour in cup'); } Coffee.prototype.addCondiments = function(){ console.log('add sugar'); } // 泡茶 var Tea = function(){}; Tea.prototype = new Beverage(); Tea.prototype.boilWater = function(){ console.log('boil water'); } Tea.prototype.brew = function(){ console.log('brew Tea'); } Tea.prototype.pourInCup = function(){ console.log('pour in cup'); } Tea.prototype.addCondiments = function(){ console.log('add lemon'); } var coffee = new Coffee(); coffee.init(); var tea = new Tea(); tea.init();
var Beverage = function(param){ var boilWater = param.boilWater || function(){}; var brew = param.brew || function(){}; var pourInCup = param.pourInCup || function(){}; var addCondiments = param.addCondiments || function(){}; var F = function(){}; F.prototype.init = function(){ boilWater(); brew(); pourInCup(); addCondiments(); } return F; } var Coffee = Beverage({ boilWater: function(){ console.log('boil water'); }, brew: function(){ console.log('brew Coffee'); }, pourInCup: function(){ console.log('pour in cup'); }, addCondiments: function(){ console.log('add sugar'); } }) var Tea = Beverage({ boilWater: function(){ console.log('boil water'); }, brew: function(){ console.log('brew Tea'); }, pourInCup: function(){ console.log('pour in cup'); }, addCondiments: function(){ console.log('add lemon'); } }) var coffee = new Coffee(); coffee.init(); var tea = new Tea(); tea.init();
The text was updated successfully, but these errors were encountered:
No branches or pull requests
实现1:
实现2:
The text was updated successfully, but these errors were encountered: