Return to Snippet

Revision: 6997
at June 30, 2008 11:08 by johnloy


Initial Code
/* 
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.

*/

Initial URL

                                

Initial Description

                                

Initial Title
Shared singleton pattern

Initial Tags
javascript, textmate

Initial Language
Other