mirror of
https://github.com/flynx/Course-JavaScript.git
synced 2025-10-30 11:30:07 +00:00
tweaking...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
f2febc8b61
commit
4d24787244
16
js-oop.js
16
js-oop.js
@ -24,6 +24,13 @@
|
|||||||
var b = Object.create(a)
|
var b = Object.create(a)
|
||||||
b.z = 3
|
b.z = 3
|
||||||
|
|
||||||
|
// Another way to do this:
|
||||||
|
|
||||||
|
var b = {
|
||||||
|
__proto__: a,
|
||||||
|
z: 3,
|
||||||
|
}
|
||||||
|
|
||||||
// The object 'b' now has both access to it's own attributes ('z') and
|
// The object 'b' now has both access to it's own attributes ('z') and
|
||||||
// attributes of 'a' ('x' and 'y')
|
// attributes of 'a' ('x' and 'y')
|
||||||
|
|
||||||
@ -68,7 +75,8 @@
|
|||||||
Object.keys(b) // -> z
|
Object.keys(b) // -> z
|
||||||
|
|
||||||
// show all accessible keys...
|
// show all accessible keys...
|
||||||
for(var k in b){ console.log(k) }
|
for(var k in b){
|
||||||
|
console.log(k) }
|
||||||
// -> x, y, z
|
// -> x, y, z
|
||||||
|
|
||||||
// Another way to test if the attribute is own/local
|
// Another way to test if the attribute is own/local
|
||||||
@ -100,9 +108,9 @@
|
|||||||
// this:
|
// this:
|
||||||
|
|
||||||
function clone(from){
|
function clone(from){
|
||||||
var o = {}
|
return {
|
||||||
o.__proto__ = from
|
__proto__: from,
|
||||||
return o
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var c = clone(b)
|
var c = clone(b)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user