Fix interpolation of inherited object properties.
This commit is contained in:
Родитель
84e58f1ee5
Коммит
bb61f88aaf
|
@ -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];
|
||||
}
|
||||
}
|
||||
|
|
Различия файлов скрыты, потому что одна или несколько строк слишком длинны
|
@ -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");
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче