I have been working a lot with JavaScript lately and have created several large collections of functions. I found the need to have auxiliary functionality that I want to separate from the main library, but I will still be included in the main library, but I have not yet found an elegant enough way to do this.
Here are some examples that I am currently using.
So, I usually set up my main library as
var animals = function(settings){
}
To add helper classes / helper functions that are encapsulated separately but still part of the main library ...
This is the first method using object literal notation.
animals.prototype.dogs = {
addDog: function(){
var test = this;
},
removeDog: function(){}
}
var animalsInstance = new animals({a: 1, b: 3});
animalsInstance.dogs.addDog();
, , dog.
animals.prototype.dogs = function(){
var parent = this;
return {
addDog: function(){
var test = parent;
var test2 = this;
},
removeDog: function(){}
}
}
var animalsInstance = new animals({a: 1, b: 3});
animalsInstance.dogs().addDog();
. , .
- - ?