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

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

php - joomla get content in onBeforeCompileHead function -