Last active
January 24, 2016 04:58
-
-
Save DuaneNielsen/77a6a0ff63e45fbb5910 to your computer and use it in GitHub Desktop.
Template for creating a node module that behaves like an object
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
| 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