I am using a closure to create an object with private and public methods. It looks like this -
var Dog = (function() {
function Dog() {}
var size = 'big';
var _privateSaySize = function() {
return 'I am a ' + size + ' dog.';
}
Dog.prototype.publicSaySize = function() {
return _privateSaySize();
}
return Dog;
})();
But now I would like to have an object that has only private functions and that is inherited by another object. But is this possible in JavaScript?
No, You can't.
JavaScript inheritance is prototype based, so You can "extend" only methods in prototype.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With