Created
April 19, 2013 13:38
-
-
Save jeffmarshall/5420414 to your computer and use it in GitHub Desktop.
I have two constructors in two separate files that have to depend on each other in their methods. Is it okay to put the 'require' call inside the methods that depend on the other models?
This file contains 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
// '/models/a.js' | |
function A(){ | |
this.type = 'a' | |
} | |
A.prototype.delete = function deleteA(callback){ | |
var self = this; | |
self.findAllBs(function(err, res){ | |
res.forEach(function(b){ | |
var b = new B(b); | |
b.delete(); | |
}); | |
}); | |
} | |
// '/models/b.js' | |
function B(){ | |
this.type = 'b' | |
} | |
B.prototype.read = function readB(callback){ | |
var self = this; | |
var myA = new A(self.a) | |
myA.read(function(err, res){ | |
return callback(null, 'My A:'+ res); | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment