CodeMirror 자바 스크립트 코드 편집기에서 메서드를 호출하는 중입니다. 나는 자바 스크립트에 익숙하지 않고 객체 지향적 인 것들이 어떻게 작동하는지 이해하려고 노력하고있다. 내가 믿는 것을 방법이라고 부르는 데 문제가 있습니다. 예를 들어,프로토 타입 메서드 호출 이해
var editor = CodeMirror.fromTextArea('code', options);
editor.grabKeys(function(e) { alert("Key event");});
이렇게하면 Uncaught TypeError: Cannot call method 'grabKeys' of undefined
이됩니다. editor
개체를 보면 grabKeys가 editor.__proto__.grabKeys
에있는 것으로 보입니다.
어떻게 생각해야합니까?
http://www.javascriptkit.com/javatutors/proto.shtml : 여기
을 위해 무엇 프로토 타입 방법 전화의 좋은 설명입니다 ..var editor = new CodeMirror.fromTextArea('code', options);
editor.grabKeys(function(e) { alert("Key event");});
공지 사항 '새'연산자 :
'CodeMirror.fromTextArea ('code', options)처럼 보이며''undefined'를 반환합니다. 어쩌면 그 함수에 잘못된 인수를 전달하고 있을까요? – harto
내가 console.log (편집자)라면 내가 탐색 할 수있는 객체로 반환됩니다. – Tristan