/ Published in: Other

Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/* A similar pattern to the module pattern is the “shared singleton†— create a singleton object for an application that can be used to share properties or methods between pages or inline frames. Here’s the start of a “my.js†script that every page or frame in an application could share: */ if (typeof parent.my != “undefinedâ€) { var my = parent.my; // shared singleton } else { var my = {}; my.something … } /* The “parent†bit is so that the script can be used with iframes and still retain a reference to the same “my†instance. If a page is at the top, then parent points to itself. Every page or frame that imports “my.js†can share properties or methods with any other page. */
Comments
