Framework: how to reuse functions in the core framework? javascript in this case
In a js framework there is a little problem: I want to reuse the code in the framework and outside it but it gets complicated;
when you want to add any klasses or helper functions it's done like this
TStore.add({
path: 'isArray',
uses: ['inArray', 'someThingElse'],
fn: function(l /*lib reference*/, u /* uses reference */){
return function(array, item){
/* stuff that calculates the array */
return true; /* or false */
}
}
})
now the problem is that when you call the method on TStore.add(...), this function will use the "inArray" that is the above function; I would like to reuse that code, instead of writing another time the same thing.
EDIT: The TStore.add method explanation
TStore.add = function(o){
(...)
// here I need to use the "inArray" function
// but I haven't it yet!
// ex:
var uses = o.uses;
if(this('isArray', uses)){
// do something
// but "isArray" is not available before
// I don't add it like this: TStore.add({...})
// like the 1º script, above
开发者_JS百科 }
}
I think a lot of software (low level) finds this problem and is already solved, but I can't find a stable solution.
It seems like this problem could be solved by adding an extra layer of logic before you define TStore.add
精彩评论