반응형 JavaScript1 [JavaScript] 콜백 함수 내부의 this를 호출 객체로 사용하는 방법 that == this function Prefixer(prefix) { this.prefix = prefix } Prefixer.prototype.prefixArray = function (arr) { var that = this; return arr.map(function (x) { return that.prefix + ' ' + x; }); }; var pre = new Prefixer('Hi'); console.log(pre.prefixArray(['Lee', 'Kim'])); // ["Hi Lee", "Hi Kim"] map(func, this) function Prefixer(prefix) { this.prefix = prefix; } Prefixer.prototype.prefixArray =.. 2023. 2. 20. 이전 1 다음 반응형