sledgeweight
sledgeweight

Reputation: 8115

Object or function in module pattern OO JS?

Recently started writing modularised js and I'm starting to notice the numerous ways one can write them.

I know the core principles of when to use an object literal or function but whats the beneficiaries of writing a module as an object literal or function on a larger scale development? Portability, flexibilty, maintainability?

var filterOverlays = { ..code .. };

var filterOverlays = function() { ..code ..}

Call in another page:

$(document).ready(filterOverlays.init);

filterOverlays();

Upvotes: 2

Views: 51

Answers (1)

harun
harun

Reputation: 1919

It might worth reading about Javascript AMD leaning towards functions. It can provide useful input for your decision.

https://github.com/amdjs/amdjs-api/wiki/AMD

http://requirejs.org/docs/whyamd.html

Upvotes: 1

Related Questions