I have been creating several classes but I never had any that needed parameters on the class itself.
The following code works perfectly.
$(function()
{
search.anotherFunction('a', 'b');
});
search = function()
{
this.anotherFunction = function(param1, param2)
{
// do whatever
};
var public = { anotherFunction: anotherFunction }
return public;
}();
But now I would like to pass parameters inside search in order to avoid passing the same parameters to all the functions.
$(function()
{
search('front/file.php').anotherFunction('a', 'b');
});
search = function(url)
{
this.anotherFunction = function(param1, param2)
{
// use here the 'url' parameter
};
this.anotherFunctionB = function(param1, param2)
{
// use here the 'url' parameter
};
var public = { anotherFunction: anotherFunction,
anotherFunctionB: anotherFunctionB }
return public;
}();
This doesn't work and the console outputs the error.
Uncaught TypeError: object is not a function
It means that search isn't a function but yes a class name and therefore can't receive params?
anotherFunction: anotherFunctionshould beanotherFunction: this.anotherFunction. Same goes foranotherFunctionB.onClickevent.