Skip to content

Instantly share code, notes, and snippets.

@mchelen
Last active December 5, 2017 04:12
Show Gist options
  • Save mchelen/ba0fcc5c2ccc7a12cce419a87837065f to your computer and use it in GitHub Desktop.
Save mchelen/ba0fcc5c2ccc7a12cce419a87837065f to your computer and use it in GitHub Desktop.
accessing an object property in node async
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();
{
"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