Fix interpolation of inherited object properties.

This commit is contained in:
Jason Davies 2012-02-20 08:52:45 +00:00
Родитель 84e58f1ee5
Коммит bb61f88aaf
4 изменённых файлов: 24 добавлений и 11 удалений

12
d3.v2.js поставляемый
Просмотреть файл

@ -1006,16 +1006,20 @@ d3.interpolateArray = function(a, b) {
d3.interpolateObject = function(a, b) {
var i = {},
c = {},
a_ = {},
b_ = {},
k;
// Workaround for inconsistent behavior of propertyIsEnumerable.
for (k in b) b_[k] = b[k];
for (k in a) {
if (b.propertyIsEnumerable(k)) {
i[k] = d3_interpolateByName(k)(a[k], b[k]);
if (Object.hasOwnProperty.call(b_, k)) {
i[k] = d3_interpolateByName(k)(a_[k] = a[k], b[k]);
} else {
c[k] = a[k];
c[k] = a_[k] = a[k];
}
}
for (k in b) {
if (!a.propertyIsEnumerable(k)) {
if (!Object.hasOwnProperty.call(a_, k)) {
c[k] = b[k];
}
}

6
d3.v2.min.js поставляемый

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Просмотреть файл

@ -194,16 +194,20 @@ d3.interpolateArray = function(a, b) {
d3.interpolateObject = function(a, b) {
var i = {},
c = {},
a_ = {},
b_ = {},
k;
// Workaround for inconsistent behavior of propertyIsEnumerable.
for (k in b) b_[k] = b[k];
for (k in a) {
if (b.propertyIsEnumerable(k)) {
i[k] = d3_interpolateByName(k)(a[k], b[k]);
if (Object.hasOwnProperty.call(b_, k)) {
i[k] = d3_interpolateByName(k)(a_[k] = a[k], b[k]);
} else {
c[k] = a[k];
c[k] = a_[k] = a[k];
}
}
for (k in b) {
if (!a.propertyIsEnumerable(k)) {
if (!Object.hasOwnProperty.call(a_, k)) {
c[k] = b[k];
}
}

Просмотреть файл

@ -30,6 +30,11 @@ suite.addBatch({
"interpolates objects with default object prototype properties": function(interpolate) {
assert.deepEqual(interpolate({foo: 2, hasOwnProperty: 1}, {foo: 12})(1), {foo: 12, hasOwnProperty: 1});
},
"interpolates inherited properties of objects": function(interpolate) {
var a = Object.create({foo: 0}),
b = Object.create({foo: 2});
assert.deepEqual(interpolate(a, b)(.5), {foo: 1});
},
"doesn't interpret properties in the default object's prototype chain as RGB": function(interpolate) {
assert.equal(interpolate("hasOwnProperty", "hasOwnProperty")(0), "hasOwnProperty");
}