decorators/@autobind: Minor improvements.
This commit is contained in:
parent
94703492fd
commit
3f6e5b7606
@ -31,25 +31,22 @@ export const autobind = (target, key, {
|
|||||||
enumerable,
|
enumerable,
|
||||||
|
|
||||||
get () {
|
get () {
|
||||||
const bounded = bind(fn, this)
|
if (this === target) {
|
||||||
|
return fn
|
||||||
|
}
|
||||||
|
|
||||||
|
const bound = bind(fn, this)
|
||||||
|
|
||||||
defineProperty(this, key, {
|
defineProperty(this, key, {
|
||||||
configurable: true,
|
configurable: true,
|
||||||
enumerable: false,
|
enumerable: false,
|
||||||
value: bounded,
|
value: bound,
|
||||||
writable: true
|
writable: true
|
||||||
})
|
})
|
||||||
|
|
||||||
return bounded
|
return bound
|
||||||
},
|
},
|
||||||
set (newValue) {
|
set (newValue) {
|
||||||
if (this === target) {
|
|
||||||
// New value directly set on the prototype.
|
|
||||||
delete this[key]
|
|
||||||
this[key] = newValue
|
|
||||||
} else {
|
|
||||||
// New value set on a child object.
|
|
||||||
|
|
||||||
// Cannot use assignment because it will call the setter on
|
// Cannot use assignment because it will call the setter on
|
||||||
// the prototype.
|
// the prototype.
|
||||||
defineProperty(this, key, {
|
defineProperty(this, key, {
|
||||||
@ -59,7 +56,6 @@ export const autobind = (target, key, {
|
|||||||
writable: true
|
writable: true
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
|
Loading…
Reference in New Issue
Block a user