How to inherit one object from another while objects are created using object literals in javascript

Posted by rajakvk on Stack Overflow See other posts from Stack Overflow or by rajakvk
Published on 2010-06-11T10:07:04Z Indexed on 2010/06/11 10:13 UTC
Read the original article Hit count: 291

Filed under:

I hope this will work

var Human = function() {
   this.name = "baby";
   this.age = 0;
}
var Man = function() {
   this.sex = male;
}
Man.prototype = Human;

But

var Human = {
    name:"baby",
    age:0
};
var Man = {
    sex:"male"
};

How to inherit one object from another while objects are created using object literals in javascript?

© Stack Overflow or respective owner

Related posts about JavaScript