JavaScript에 대한 실제 지식을 얻으려고합니다. 그래서 더글라스 크록 포드 (Douglas Crockford)의 "자바 스크립트 좋은 부분"이라는 책을 샀습니다.자바 스크립트 - 프로토 타입
현재 프로토 타입을 파악하는 데 어려움을 겪고 있습니다. 아래의 모든 것은 // PROTOTYPE 예제를 칠 때까지 내 브라우저에서 작동하는 것 같습니다. 누군가가 그것을 볼 수있어 왜 내가 그것에서 어떤 출력을 얻을 수 없는지. (프로토 타입 코드를 모두 주석 처리하지 않으면 내 페이지가 공백으로 표시됩니다.)
감사합니다.
베리
var stooge = {
"first-name": "Jerome",
"last-name": "Howard",
"nickname": "J",
"profession" : 'Actor'
};
// below is augmenting
var st = stooge;
st.nickname = "curly";
// st.nickname and nick are the same because both are ref's to the same object
var nick = st.nickname;
document.writeln(stooge['first-name']); //expect Jerome -- this is "suffix" retrieval
document.writeln(st.nickname); //expect "curly" -- this is "notation" retrieval
document.writeln(nick); //expect "curly"
document.writeln(stooge.profession);
//PROTOTYPE EXAMPLE;
if (typeof Object.create !== 'function')
{
object.create = function(o) {
var F = function() {};
F.prototype = o;
return new F();
};
var another_stooge = Object.create(stooge);
another_stooge['first-name'] = 'Barry';
document.writeln(another_stooge['first-name']);
// the below should be inherited from the prototype therefore "Actor"
document.writeln(another_stooge.profession);
Tim, 고마워요. Tim : 실례합니다. – CaRDiaK
@ 퍼디난드 : 좋은 편집, 고마워. –