Last active
December 5, 2017 04:12
-
-
Save mchelen/ba0fcc5c2ccc7a12cce419a87837065f to your computer and use it in GitHub Desktop.
accessing an object property in node async
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const async = require('async'); | |
function myObject (text) { | |
this.text = text; | |
} | |
myObject.prototype.run = function (callback) { | |
async.parallel( | |
[ | |
this.doing, | |
this.doing, | |
this.doing, | |
], | |
this.done | |
); | |
} | |
myObject.prototype.doing = function (callback) { | |
callback(null, "hello") | |
} | |
myObject.prototype.done = function (err, results) { | |
console.log(results); // [ 'hello', 'hello', 'hello' ] | |
console.log(this.text); // undefined | |
} | |
myObj = new myObject("world"); | |
myObj.run(); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "ba0fcc5c2ccc7a12cce419a87837065f", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"dependencies": { | |
"async": "^2.6.0" | |
}, | |
"devDependencies": {}, | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"repository": { | |
"type": "git", | |
"url": "git+ssh://[email protected]/ba0fcc5c2ccc7a12cce419a87837065f.git" | |
}, | |
"author": "", | |
"license": "ISC", | |
"bugs": { | |
"url": "https://gist.github.com/ba0fcc5c2ccc7a12cce419a87837065f" | |
}, | |
"homepage": "https://gist.github.com/ba0fcc5c2ccc7a12cce419a87837065f" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment