bind-obj-methods
Advanced tools
Comparing version 1.0.0 to 2.0.0
@@ -1,10 +0,8 @@ | ||
module.exports = bindObj | ||
'use strict' | ||
function bindObj (obj, proto, bound) { | ||
module.exports = (obj, proto, bound) => { | ||
bound = bound || Object.create(null) | ||
if (Array.isArray(bound)) | ||
bound = bound.reduce(function (set, k) { | ||
set[k] = true | ||
return set | ||
}, Object.create(null)) | ||
bound = bound.reduce((s, k) => (s[k] = true, s), Object.create(null)) | ||
@@ -15,20 +13,14 @@ // don't try to bind constructors, it's weird | ||
Object.keys(proto).forEach(function (k) { | ||
if (typeof obj[k] === 'function' && !bound[k]) { | ||
bound[k] = true | ||
obj[k] = proto[k].bind(obj) | ||
} | ||
}) | ||
Object.keys(proto) | ||
.filter(k => (typeof obj[k] === 'function' && !bound[k])) | ||
.forEach(k => (bound[k] = true, obj[k] = proto[k].bind(obj))) | ||
Object.getOwnPropertyNames(proto).forEach(function (k) { | ||
if (typeof obj[k] === 'function' && !bound[k]) { | ||
bound[k] = true | ||
Object.defineProperty(obj, k, { | ||
value: obj[k].bind(obj), | ||
enumerable: false, | ||
configurable: true, | ||
writable: true | ||
}) | ||
} | ||
}) | ||
Object.getOwnPropertyNames(proto) | ||
.filter(k => (typeof obj[k] === 'function' && !bound[k])) | ||
.forEach(k => (bound[k] = true, Object.defineProperty(obj, k, { | ||
value: obj[k].bind(obj), | ||
enumerable: false, | ||
configurable: true, | ||
writable: true | ||
}))) | ||
} |
{ | ||
"name": "bind-obj-methods", | ||
"version": "1.0.0", | ||
"version": "2.0.0", | ||
"description": "Bind methods to an object from that object or some other source. Optionally specify a set of methods to skip over.", | ||
"main": "bind-obj-methods.js", | ||
"scripts": { | ||
"test": "node test.js" | ||
"test": "tap test.js --100", | ||
"preversion": "npm test", | ||
"postversion": "npm publish", | ||
"postpublish": "git push origin --all; git push origin --tags" | ||
}, | ||
@@ -19,3 +22,7 @@ "author": "Isaac Z. Schlueter <i@izs.me> (http://blog.izs.me/)", | ||
}, | ||
"homepage": "https://github.com/isaacs/bind-obj-methods#readme" | ||
"homepage": "https://github.com/isaacs/bind-obj-methods#readme", | ||
"devDependencies": { | ||
"tap": "^10.7.0" | ||
}, | ||
"files": [] | ||
} |
@@ -31,3 +31,4 @@ # bind-obj-methods | ||
bindObjMethods(obj) | ||
m = obj.method | ||
m() // 'bar' | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
34
2985
1
4
20