Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5
Hello, Albert Mungochi ! There is not much choice between the two methods. The basic idea is that when the JavaScript engine is given an object property for reading, it first checks the instance, and if this property is not present, it checks the prototype chain. Here is an example that shows the difference between a prototype and a classic: prototypical var single = {status: "Single"},     princeWilliam = Object.create (single),     cliffRichard = Object.create (single); console.log (Object.keys (princeWilliam) .length); // 0 console.log (Object.keys (cliffRichard) .length); // 0 // Marriage event occurs princeWilliam.status = "Married"; console.log (Object.keys (princeWilliam) .length); // 1 (New instance property) console.log (Object.keys (cliffRichard) .length); // 0 (Still refers to prototype) The classic instance method (inefficient, because each instance preserves its own property)
19th Jun 2018, 5:29 AM
Alexander Sokolov
Alexander Sokolov - avatar