1
나는 객체 A를 생성하고 싶습니다, 그래서 같이 쓰기 :"A.fn.A.init {}"의 의미는 무엇입니까?
는A = function() {
}
A.prototype = {
init: function() {
console.log(this);
}
}
new A.prototype.init()
의 결과는 A.init {}
입니다.
나는이 같은 A.prototype의 별칭을 만들 때 :
A = function() {
}
A.as = A.prototype = {
init: function() {
console.log(this);
}
}
결과는 A.as.A.init {}
대신 A.init {}
으로 밝혀졌다.
왜? this
은 어떻게 작동합니까?
예상되는 결과는 무엇입니까? – guest271314
"* 새로운 A.prototype.init()의 결과 *"하지 마라. 원하는 경우'new A' 인스턴스를 만들고'init' 메소드를 드롭하십시오. – Bergi