Created
December 27, 2013 03:29
-
-
Save zhangwc/8142232 to your computer and use it in GitHub Desktop.
公开数据到指定域中,在加载js文件时,立即执行
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * I want to expose in your name to the specified data. | |
| * @param {*} Data published | |
| * @param {String} alias External publication of name. From the reference scope, I specify a relative name, including the namespace name | |
| * @param {Object} [scope=window] Data release position | |
| * @return {Boolean} If true, data published | |
| */ | |
| MeObject.expose = function(data, alias, scope) { | |
| scope = scope || window; | |
| try { | |
| var parts = alias.split("."); | |
| for (var i = 0, len = parts.length; i < len; i++) { | |
| var part = parts[i]; | |
| if (i == len-1) { | |
| scope[part] = data; | |
| } | |
| else { | |
| scope = scope[part] || (scope[part] = {}); | |
| } | |
| } | |
| } | |
| catch(err) { | |
| return false; | |
| } | |
| // If the inheritance class or MeObject, to update the alias | |
| if (data && (data == MeObject || (data.prototype instanceof MeObject))) { | |
| data.prototype.alias = alias; | |
| } | |
| return true; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment