Object.create and Prototype Experiments

by andypotanin

JavaScript

var test = Object.defineProperties( function Whatever( name ) { 
    this.name = name;         
    this.prototype = Whatever.prototype;     
    return this;
}, {
    "constructor": {
        "value": function Whatever2() {},
        "enumerable": true,
        "configurable": true,
        "writable": true
    },
    "prototype": {
        "value": {
            "thing": function Thing() {},
            "create": Object.create
        }
    }
});


console.clear();

console.log( 'test', Object.keys( test ) );
console.log( 'test', typeof test, test.name );
console.log( 'test.constructor.name', typeof test.constructor, test.constructor.name );
console.log( 'test.prototype', typeof test.prototype );
console.log( 'test.prototype.thing', typeof test.prototype.thing, test.prototype.thing.name );
console.log( 'test.prototype.create', typeof test.prototype.create, test.prototype.create.name );

var tits = new test( 'Tits' );

console.log( 'tits', Object.keys( tits ) );
console.log( 'tits', typeof tits, tits.name );
console.log( 'tits.constructor.name', typeof tits.constructor, tits.constructor.name );
console.log( 'tits.prototype', typeof tits.prototype );
console.log( 'tits.prototype.create', typeof tits.prototype.create, tits.prototype.create.name );

var blah = tits.create( test.prototype, { 
    "name": {
        "value": "My Name"
    },
    "prototype": {
        "value": test.prototype
    },
    "blah": {
        "value": "true",
        "enumerable": true
    }
});

console.log( 'blah', Object.keys( blah ) );
console.log( 'blah', typeof blah, blah.name );
console.log( 'blah.constructor.name', typeof blah.constructor, blah.constructor.name );
console.log( 'blah.prototype', typeof blah.prototype );
console.log( 'blah.prototype.create', typeof blah.prototype.create, blah.prototype.create.name );