Wrapping methods up in a JavaScript object -


i have need this:

<script src="apiwrapper.js"></script> <script>   apiwrapper.init('api_key');   apiwrapper.dosomethingelse(); </script> 

essentially, have singleton style object in page can add methods , properties , have available anywhere within page.

what's best way this?

you use approach (which gives way of having private properties/functions):

var apiwrapper = apiwrapper || (function () {    /* private functions here */   var privatefunction = function () {   }    /* public functions here */   return {     init: function (opts) {},     dosomethingelse: function () {}   }; })(); 

Comments

Popular posts from this blog

android - Inheriting from Theme.AppCompat* -

broadcastreceiver - android BOOT_COMPLETED not received if not activity intent-filter -

basic authentication with http post params android -