Last active
July 29, 2021 06:04
-
-
Save eamon0989/a82b03b64d53e9d41454655d3712ebf3 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
function objectFactory() { | |
return { | |
property1: 'My first property', | |
property2: 'My second property', | |
printProperties() { | |
for (let prop in this) { | |
if (typeof this[prop] !== 'function') { | |
console.log(`${prop}: ${this[prop]}`); | |
} | |
} | |
} | |
}; | |
} | |
let object = objectFactory(); | |
let object1 = objectFactory(); | |
console.log(object); | |
console.log(object1); | |
/* | |
{ | |
property1: 'My first property', | |
property2: 'My second property', | |
printProperties: [Function: printProperties] | |
} | |
{ | |
property1: 'My first property', | |
property2: 'My second property', | |
printProperties: [Function: printProperties] | |
} | |
*/ | |
console.log(Object.getPrototypeOf(object) === Object.prototype); // true | |
console.log(Object.getPrototypeOf(object1) === Object.prototype); // true | |
console.log(object instanceof objectFactory); // false | |
Object.setPrototypeOf(object, objectFactory.prototype); | |
console.log(object instanceof objectFactory); // true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment