prototype: Remove the now redundant forked declaration of Hash#_each.
This commit is contained in:
parent
0b6a6e2f2f
commit
74c005c678
|
@ -1,3 +1,5 @@
|
|||
* Remove the forked declaration of Hash#_each. As we are now systematically cloning the object upon instantiation, preventing iteration of shadowed properties is no longer required. [Tobie Langel]
|
||||
|
||||
* Performance optimizations for Event#findElement. Make Event#findElement's expression argument optional, in which case the extended target element is returned (same as Event#element). [Tobie Langel]
|
||||
|
||||
* Ensure Event#fire always returns an extended event. [Tobie Langel]
|
||||
|
|
39
src/hash.js
39
src/hash.js
|
@ -3,35 +3,7 @@ function $H(object) {
|
|||
};
|
||||
|
||||
var Hash = Class.create(Enumerable, (function() {
|
||||
if (function() {
|
||||
var i = 0, Test = function(value) { this.key = value };
|
||||
Test.prototype.key = 'foo';
|
||||
for (var property in new Test('bar')) i++;
|
||||
return i > 1;
|
||||
}()) {
|
||||
function each(iterator) {
|
||||
var cache = [];
|
||||
for (var key in this._object) {
|
||||
var value = this._object[key];
|
||||
if (cache.include(key)) continue;
|
||||
cache.push(key);
|
||||
var pair = [key, value];
|
||||
pair.key = key;
|
||||
pair.value = value;
|
||||
iterator(pair);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
function each(iterator) {
|
||||
for (var key in this._object) {
|
||||
var value = this._object[key], pair = [key, value];
|
||||
pair.key = key;
|
||||
pair.value = value;
|
||||
iterator(pair);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function toQueryPair(key, value) {
|
||||
if (Object.isUndefined(value)) return key;
|
||||
return key + '=' + encodeURIComponent(String.interpret(value));
|
||||
|
@ -42,7 +14,14 @@ var Hash = Class.create(Enumerable, (function() {
|
|||
this._object = Object.isHash(object) ? object.toObject() : Object.clone(object);
|
||||
},
|
||||
|
||||
_each: each,
|
||||
_each: function(iterator) {
|
||||
for (var key in this._object) {
|
||||
var value = this._object[key], pair = [key, value];
|
||||
pair.key = key;
|
||||
pair.value = value;
|
||||
iterator(pair);
|
||||
}
|
||||
},
|
||||
|
||||
set: function(key, value) {
|
||||
return this._object[key] = value;
|
||||
|
|
|
@ -213,6 +213,17 @@
|
|||
assertEqual("hello world", template.evaluate(hash.toObject()));
|
||||
assertEqual("hello world", template.evaluate(hash));
|
||||
assertEqual("hello", "#{a}".interpolate(hash));
|
||||
}},
|
||||
|
||||
testPreventIterationOverShadowedProperties: function() { with(this) {
|
||||
// redundant now that object is systematically cloned.
|
||||
var FooMaker = function(value) {
|
||||
this.key = value;
|
||||
};
|
||||
FooMaker.prototype.key = 'foo';
|
||||
var foo = new FooMaker('bar');
|
||||
assertEqual("key=bar", new Hash(foo).toQueryString());
|
||||
assertEqual("key=bar", new Hash(new Hash(foo)).toQueryString());
|
||||
}}
|
||||
|
||||
}, 'testlog');
|
||||
|
|
Loading…
Reference in New Issue