How do I implement inheritance in javascript?

javascript, jquery, knockout.js

Solution

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 () {}
    });

Problem

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?

Original source

Related problems