Object Create ( ) Method

Video

JavaScript Notes

JavaScript
    // Object.create(prototype, propertiesObject) method
    // propertiesObject same as 2nd argument from Object.defineProperties( )
    
    let obj = {
          name: 'The Dude'
    };
    
    let obj2 = Object.create(obj, { });
    console.log(obj2);			// returns empty object { }
    console.log(obj2.name);		// doesn't exist in properties of obj2, so looks up the prototype chain, the name: ‘The Dude’, from obj
    
    let obj3 = Object.create(obj2, { 
    	fullName: {
    		configurable: true,
    		writable: true,
    		enumerable: true,
    		value: 'Jeff Lebowski'
    	},
    	canBowl: {
    		configurable: true,
    		writable: true,
    		enumerable: true,
    		value: true
    	}
    });
    console.log(obj3);			// will return fullName, and canBowl
    console.log(obj3.name);		// will return name (from obj)