Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you inherit private functions in JavaScript? [closed]

Tags:

javascript

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?

like image 586
csss Avatar asked Jul 15 '13 10:07

csss


1 Answers

No, You can't.

JavaScript inheritance is prototype based, so You can "extend" only methods in prototype.

like image 99
Radosław Miernik Avatar answered Sep 18 '22 18:09

Radosław Miernik