How do I implement inheritence in Javascript? I am getting started with Knockout.js and implementing ViewModels/page. However I have some functions/code that I want it shared across all ViewModels.
I was wondering how do I implement inheritence in this case?
Inheritance might not necessarily be the answer. Why not create an object literal with all the methods that each ViewModel should implement. I am unfamiliar with knockout, but here's how you might do it in native js.
    var sharedMethods = {
             run: function () {},
             jump: function () {}
        };
    function Person () {};
    // Use jQuery's extend method
    // Now person has run, jump, and talk
    $.extend(Person.prototype, sharedMethods, {
        talk: function () {}
    });
                        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