Qual é a diferença na invocação de 'isto' nesses exemplos?
Estou lendo 'JS: The Good Parts' de Crockford. Ele tem dois exemplos usando isso e eu não entendo porque em uma instância ele usathis
e em outro ele usathat
.
O primeiro exemplo:
String.method('deentify', function() {
var entity = {
quot: '"',
lt: '<',
gt: '<'
};
return function() {
return this.replace(/&([^&;]+);/g,
function (a, b) {
var r = entity[b];
return typeof r === 'string' ? r : a;
}
);
};
}());
document.writeln('<">'.deentify());
O segundo exemplo:
Function.method('curry', function() {
var args = arguments, that = this;
return function () {
return that.apply(null, args.concat(arguments));
};
});
var add1 = add.curry(1);
document.writeln(add1(6));
Por que o primeiro exemplo pode acessarthis
diretamente? Qual é a diferença entre esse exemplo e aquele que o segue?