run-objfun
v1.0.6
Published
functions in running objects(运行对象中的函数)
Downloads
6
Maintainers
Readme
run-objFun
Functions in running objects
install
# Install with npm
$ npm install run-objfun --save
# Install with yarn
$ yarn add run-objfun
# Install with bower
$ bower install run-objfun --save
Usage
function is ES5 or ES6
const runObjFun = require('run-objfun')
let arr = []
const fun1 = () => {
arr.push(1)
}
const fun2 = function() {
arr.push(2)
}
const obj = {
fun1,
fun2,
fun3: function() {
arr.push(3)
},
fun4: () => {
arr.push(4)
}
}
runObjFun(obj) //=> true
console.log(arr) //=> [1, 2, 3, 4]
Skip non object
const runObjFun = require('run-objfun')
let i = 0
const fun1 = () => { // Run successfully
++i
}
const fun2 = () => { // Run successfully
++i
}
const generator1 = function * () {
++i
}
const array1 = [1, 2, 3]
const number1 = 123
const regexp1 = /foo/
const string1 = 'string'
const bool1 = true
const bool2 = false
const undefined1 = undefined
const null1 = null
const obj = {
fun1,
fun2,
generator1,
array1,
number1,
regexp1,
string1,
bool1,
bool2,
undefined1,
null1
}
runObjFun(obj) //=> true
console.log(i) //=> 2
Type judgment
const runObjFun = require('run-objfun')
const arr = []
runObjFun(arr) //=> false
Running tests
Install dev dependencies:
$ npm i -d && npm test
Contributing
| Commits | Contributor | | --- | --- | | 7 | Black-Hole |
Author
Black-Hole
- Email:[email protected]
- Blog:http://bugs.cc
- WeiBo:http://weibo.com/comelove
- Twitter:https://twitter.com/Free_BlackHole