Skip to content

Commit 9e11b62

Browse files
committed
Made metagetter only call underlying get functions once, switched to included bind function
1 parent 2e9db42 commit 9e11b62

File tree

2 files changed

+6
-14
lines changed

2 files changed

+6
-14
lines changed

src/observer/index.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,8 @@ function defineReactive (obj, key, val) {
182182
var property = Object.getOwnPropertyDescriptor(obj, key)
183183
if (property && property.get && property.set) {
184184
Object.defineProperty(target, 'val', {
185-
get: property.get.bind(obj),
186-
set: property.set.bind(obj)
185+
get: _.bind(property.get, obj),
186+
set: _.bind(property.set, obj)
187187
})
188188
}
189189
}
@@ -193,14 +193,15 @@ function defineReactive (obj, key, val) {
193193
enumerable: true,
194194
configurable: true,
195195
get: function metaGetter () {
196+
var val = target.val
196197
if (Dep.target) {
197198
dep.depend()
198199
if (childOb) {
199200
childOb.dep.depend()
200201
}
201-
if (_.isArray(target.val)) {
202-
for (var e, i = 0, l = target.val.length; i < l; i++) {
203-
e = target.val[i]
202+
if (_.isArray(val)) {
203+
for (var e, i = 0, l = val.length; i < l; i++) {
204+
e = val[i]
204205
e && e.__ob__ && e.__ob__.dep.depend()
205206
}
206207
}

test/unit/lib/util.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,6 @@ var scope = typeof window === 'undefined'
22
? global
33
: window
44

5-
// Some versions of phantomjs doesn't have bind defined.
6-
// See https://github.com/ariya/phantomjs/issues/10522
7-
Function.prototype.bind = Function.prototype.bind || function (thisp) {
8-
var fn = this;
9-
return function () {
10-
return fn.apply(thisp, arguments);
11-
};
12-
};
13-
145
scope.hasWarned = function (_, msg, silent) {
156
var count = _.warn.calls.count()
167
while (count--) {

0 commit comments

Comments
 (0)