用于跨页面共享实用程序方法的共享单例模式
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了用于跨页面共享实用程序方法的共享单例模式相关的知识,希望对你有一定的参考价值。
/* 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. */
以上是关于用于跨页面共享实用程序方法的共享单例模式的主要内容,如果未能解决你的问题,请参考以下文章