js prototype

/**
*
*/
if(typeof Object.beget !== 'function'){
    Object.beget = function(o){
        var F = function(){};
        F.prototype = o;
        return new F();
    }
}

/*
*
*/
var foo = {
    name : 'foo',
    print: function(msg){
        console.log(msg)
    }
}
/*
*
*/
foo.print('hello')
/*
*
*/
var bar = Object.beget(foo);
bar.print('world');

你可能感兴趣的:(编程语言与框架)