DBILITY

독거 가능성 100% 노후에 라면값이라도 하게 센스를 발휘합시다!😅
Please click on the ad so that I can pay for ramen in my old age!
点击一下广告,让老后吃个泡面钱吧!
老後にラーメン代だけでもするように広告を一回クリックしてください。

javascript es5 inheritance ( 상속 ) 본문

front-end & ui/javascript

javascript es5 inheritance ( 상속 )

DBILITY 2021. 10. 29. 19:04
반응형

ES5에서는 Object.create()를 통해 가능하다고 한다.

function log(...args) {
    args.forEach(function (v, i) {
        console.log(v);
    })
}

var parent = {
    name: '부모', age: 5000
};

var child = Object.create(parent);
var grandChild = Object.create(child);

log(child);

child.name = '자식';
child.age = 10;

log(child);

grandChild.name = '손자';
grandChild.age = 2;

log(grandChild, grandChild.name);

log(grandChild.__proto__);

그림 1

반응형
Comments