0π
β
I rewrote rubles.js into classβs style
//in rubles.js
(function() {
//var somePar = [....];// and I transferred this property to the class
// I suppose that the manipulation of this array
// led to a negative result before
//add the constructor
var Rubles = function(template) {
var s = this;
s.somePar = [....];
s.getRes(n){
...
return n;
}
}
globals.Rubles = Rubles;
})();
and when
window.Rubles = require('./custom/rubles');
window.numToRubles = new window.Rubles.Rubles({nominal:true, div:true, dat:false});
window.numToString = new window.Rubles.Rubles({nominal:false, div:false, dat:true});
res1 = numToRubles.getRes(n);
res2 = numToString.getRes(n);
It works fine
0π
Try following:
window.numToRubles = require('./custom/rubles');
window.numToRubles2 = window.numToRubles.bind({});
//clones the function with '{}' acting as it's new 'this' parameter
Now
//in some.js
numToRubles.rubles(val, {nominal:true, div:true, dat:false});
numToRubles2.rubles(val, {nominal:true, div:false, dat:true});
Source:stackexchange.com