«object-create» 태그된 질문

10
Object.create ()와 new SomeFunction ()의 차이점 이해
나는 최근 Object.create()에 JavaScript 에서 메소드를 우연히 발견했으며을 사용하여 객체의 새 인스턴스를 만드는 것과 다른 점과 다른 것을 사용하려고 할 때를 추론하려고합니다 new SomeFunction(). 다음 예제를 고려하십시오. var test = { val: 1, func: function() { return this.val; } }; var testA = Object.create(test); testA.val = 2; console.log(test.func()); // 1 …

4
자바 스크립트 상속 : Object.create vs new
JavaScript에서이 두 예제의 차이점은 무엇입니까? 전제 조건 : function SomeBaseClass(){ } SomeBaseClass.prototype = { doThis : function(){ }, doThat : function(){ } } Object.create를 사용한 상속 예제 A : function MyClass(){ } MyClass.prototype = Object.create(SomeBaseClass.prototype); 새 키워드를 사용한 상속 예 B function MyClass(){ } MyClass.prototype = new SomeBaseClass(); 두 예제 …
당사 사이트를 사용함과 동시에 당사의 쿠키 정책개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.