Skip to content

Instantly share code, notes, and snippets.

@DuaneNielsen
Last active January 24, 2016 04:58
Show Gist options
  • Select an option

  • Save DuaneNielsen/77a6a0ff63e45fbb5910 to your computer and use it in GitHub Desktop.

Select an option

Save DuaneNielsen/77a6a0ff63e45fbb5910 to your computer and use it in GitHub Desktop.
Template for creating a node module that behaves like an object
var Grabber = function (url, collection) {
this.url = url;
this.filename = url.substring(url.lastIndexOf('/')+1);
this.collection = collection;
var self = this;
};
// function declaration
Grabber.prototype.init = function () {
console.log('init jobs');
this.grab(this.collection, this.url);
};
//binding a callback context to the object
Grabber.prototype.heh = function () {
// the function paramter has local object scope bound by wrapping it in a ().bind(this)
rockon( ( function () {
this.url;
} ).bind(this) )
}
module.exports = Grabber;
// to use
var Grabber = require('Grabber');
grabber = new Grabber(<url>, <collection>);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment