Last active
November 24, 2015 17:40
-
-
Save miksansegundo/ad4f0ab72ef3db234157 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var vehicle = { | |
getModel: function () { | |
console.log( "The model of this vehicle is.." + this.model ); | |
} | |
}; | |
var car = Object.create(vehicle, { | |
"id": { | |
value: MY_GLOBAL.nextId(), | |
// writable:false, configurable:false by default | |
enumerable: true | |
}, | |
"model": { | |
value: "Ford", | |
enumerable: true | |
} | |
}); | |
var model = car.getModel() | |
var id = car.id | |
// Old School | |
var create = (function () { | |
function F() {} | |
return function ( proto ) { | |
F.prototype = proto; | |
return new F(); | |
}; | |
})(); | |
var childObject = create(parentObject) | |
// New School | |
var childObject = Object.create(parentObject) | |
// Adding a property to a object using Object.defineProperty | |
Object.defineProperty( childObject, 'propertyName', { | |
value: 3, | |
enumerable: false, // No puede recorrerse con for.. in, tampoco sale en Object.keys | |
writable: false, | |
configurable: false | |
}); | |
ob.c; // => 3 | |
Object.getOwnPropertyDescriptor( ob, 'c' ); | |
// => {value: 3, enumerable: false, writable: false, configurable: false} | |
Object.assign({}, obj1, obj2) // Clona o fusiona solo las propiedades enumerables |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment