我正在学习 OO JavaScript,所以这个问题可能听起来很奇怪。问题:normalize
函数应该是私有的,外部不可访问/可写。问题:如何从原型函数normalize
内部访问?prepare
var AuthHmac = AuthHmac || (function(_, CryptoJS) {
function AuthHmac(options) {
var options = options || {},
normalize = function(s) { return s.toLowerCase(); };
this.additionalHeaders = options.additionalHeaders || {};
};
AuthHmac.prototype.prepare = function(request) {
request.headers = request.headers || {};
_.each(this.additionalHeaders, function(value, name) {
request.headers[this.normalize(name)] = value;
});
};
return AuthHmac;
})(_, CryptoJS);