1.

Write A Code For The Implementation Of A Module Pattern?

Answer»

The OBJECT literal does not provide any privacy for the methods or properties. The module PATTERN allows the user to offer privacy to functions and variables. It can be USED to SET to expose limited API.

For example: The module pattern code:

var FEATURE =(function() { var privateThing = 'secret', publicThing = 'not secret', changePrivateThing = function() { privateThing = 'super secret'; }, sayPrivateThing = function() { console.log(privateThing); changePrivateThing(); }; return { publicThing : publicThing, sayPrivateThing : sayPrivateThing } })(); feature.publicThing; // 'not secret' feature.sayPrivateThing();

The object literal does not provide any privacy for the methods or properties. The module pattern allows the user to offer privacy to functions and variables. It can be used to set to expose limited API.

For example: The module pattern code:



Discussion

No Comment Found