Skip to content Skip to sidebar Skip to footer

Set My Var To An Anonymous Function With A Parameter?

I'm building my first OO JS library and im having a little trouble with one piece that's probably super easy... I have this: var storageLocker = function(catalog){ if(catalog){

Solution 1:

Remove the () at the end of the function body.

You wrote var storageLocker = function(...) { ... }(), which creates an anonymous function, calls it, and assigns the result to storageLocker.

It's equivalent to

functionanonymous(...) { ... };
var storageLocker = anonymous();

Since the function doesn't return anything, storageLocker ends up being undefined, and is not a function.

Post a Comment for "Set My Var To An Anonymous Function With A Parameter?"