Native Prototypes Flashcards
let obj = {}; alert( obj ); //
“[object Object]” ?
obj = {} is the same as obj = new Object()
TRUE / FALSE
TRUE
When new Object() is called (or a literal object {…} is created), the [[Prototype]] of it is set to ________
object.prototype
when obj.toString() is called the method is taken from ____________
Object.prototype.
let arr = [1, 2, 3];
// it inherits from Array.prototype? alert( \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_ ); // true
arr.__proto__ === Array.prototype
let arr = [1, 2, 3];
// it inherits from Array.prototype? alert( arr.\_\_proto\_\_ === Array.prototype ); // ?
true
let arr = [1, 2, 3];
// then from Object.prototype? alert( \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_ ); // true
arr.__proto__.__proto__ === Object.prototype
let arr = [1, 2, 3];
// then from Object.prototype? alert( arr.\_\_proto\_\_.\_\_proto\_\_ === Object.prototype ); //
true
let arr = [1, 2, 3];
// and null on the top. alert( \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_); // null
arr.__proto__.__proto__.__proto__
let arr = [1, 2, 3];
// and null on the top. alert( arr.\_\_proto\_\_.\_\_proto\_\_ ); //
[[object Object]]
function f() {}
alert(f.__proto__.__proto__ == Function.prototype); //
false
function f() {}
alert(f.__proto__. == Function.prototype); //
true
function f() {}
alert(f.__proto__.__proto__ == Object.prototype); //
true, inherit from objects
Values _______ and _________ have no object wrappers
null
undefined
_________ is a term for making a substitute for a method that exists in JavaScript specification, but not yet supported by current JavaScript engine
Polyfilling
The __proto__ is considered outdated and somewhat deprecated (in browser-only part of the JavaScript standard).
The modern methods are:
Object.create(proto[, descriptors]) – creates an empty object with given proto as [[Prototype]] and optional property descriptors.
Object.getPrototypeOf(obj) – returns the [[Prototype]] of obj.
Object.setPrototypeOf(obj, proto) – sets the [[Prototype]] of obj to proto.