JS module template override function

I have the following template

BASE = function () { var that = {}; var number = 10; that.showNumber = function(){ that.alertNumber(); } that.alertNumber = function () { alert(number); }; return that; }; CHILD = function () { var that = Object.create(BASE()); var secondNumber = 20; // Override base function that.alertNumber = function () { alert(secondNumber); }; return that; }; var ch = CHILD(); ch.showNumber(); 

Can you tell me how I can customize a module template inspired by Douglas Crock Ford to completely override the alerNumber function? So far, the showNumber function displays 10 instead of 20.

Thanks to everyone in the extended

JSFiddle with code here

+6
source share
1 answer

You can change

 that.showNumber = function(){ that.alertNumber(); } 

to

 that.showNumber = function(){ this.alertNumber(); } 

But I'm not sure that I see why you simply do not use the prototype database inheritance model .

+5
source

Source: https://habr.com/ru/post/946269/


All Articles