fixed a couple of bugs...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2018-04-20 13:20:15 +03:00
parent c1dbd11f5e
commit 91beb4d0d4

View File

@ -185,7 +185,8 @@
function construct(func){ function construct(func){
var obj = {} var obj = {}
return func.apply(obj) func.apply(obj)
return obj
} }
var b = construct(A) var b = construct(A)
@ -254,26 +255,26 @@
// the following three lines actually add attributes to the same // the following three lines actually add attributes to the same
// object... // object...
A.prototype.x = 123 A.prototype.k = 123
a.constructor.prototype.y = 321 a.constructor.prototype.l = 321
a.__proto__.z = 333 a.__proto__.m = 333
// for illustration, we'll set some object own attributes // for illustration, we'll set some object own attributes
a.x = 'a!' a.k = 'a!'
b.x = 'b!' b.k = 'b!'
a.x // -> 'a!' a.k // -> 'a!'
a.y // -> 321 a.l // -> 321
a.z // -> 333 a.m // -> 333
// These values are accessible from all objects constructed by A since // These values are accessible from all objects constructed by A since
// all of them point to A with both the .constructor and .__proto__ // all of them point to A with both the .constructor and .__proto__
// attributes // attributes
b.x // -> 'b!' b.k // -> 'b!'
b.y // -> 321 b.l // -> 321
b.z // -> 333 b.m // -> 333
// This works for any constructor, including built-in constructors and // This works for any constructor, including built-in constructors and
@ -292,8 +293,10 @@
Object.prototype.keys = function(){ return Object.keys(this) } Object.prototype.keys = function(){ return Object.keys(this) }
Object.prototype.allKeys = function(){ return Object.allKeys(this) } Object.prototype.allKeys = function(){ return Object.allKeys(this) }
b.keys() // -> ['x'] b.keys() // -> ['k']
b.allKeys() // -> ['x', 'y', 'z'] b.allKeys() // -> ['x', 'y', 'k', 'l', 'm']
// NOTE: x and y are set in the A constructor
// above...