2

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();
1
  • Imo it comes down to preference. Commented Feb 28, 2014 at 13:16

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.