나는 this
에 대한 질문을 JavaScript에서 가지고 있습니다.JavaScript의 "this"예약어에 대한 질문입니다.
Function.prototype.method = function (name, func) {
if (!this.prototype[name]) {
this.prototype[name] = func;
}
};
String.method('deentityify', function() {
var entity = {
quot: '"',
lt: '<',
gt: '>'
};
return function() {
/*if (this === String.prototype) {
alert('true');
} else {
alert('false');
}*/
return this.replace(/&([^&;]+);/g,
function (a, b) {
var r = entity[b];
return typeof r === 'string' ? r : a;
}
);
};
}());
document.write('<">'.deentityify());
당신은에서 위의 코드를 편집 할 수 있습니다 : 아래
체크 아웃 코드 http://jsfiddle.net/G3Tkm/
내 질문은 :
27 return this.replace(/&([^&;]+);/g,
이 줄에서 this
예약어 무엇입니까?
내가 맞춰 보면 : this === String.prototype
,하지만 그렇지 않습니다.
'<">'
유형은 문자열이며 this
유형이 대상입니다. 따라서 this !== '<">'
대단히 감사합니다. 나는에 그것의 주변 기능을 찾을 때까지 내가 자바 스크립트 코드에서 this
키워드를 찾을 때마다