⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bobject.jsc

📁 《JavaScript王者归来》examples.rar
💻 JSC
字号:
# language: jsvm2

/**
 * @fileoverview js.lang.BObject class {@link http://jsvm.org/}
 * @file		BObject.jsc
 * @author	Wan Changhua * @version	2.01, 10/23/05 * @since		JSVM2.0
 */

package js.lang;

import js.lang.System;
import js.lang.NotSupportException;


/** * Create a new BObject instance.
 * Inherit from JObject * @author	Wan Changhua * @version	2.01, 10/23/05
 * @extends JObject * @class js.lang.BObject is a class that work on browser.
 * @constructor * @throws NotSupportException if platform is not a browser * @return A new BObject
 * @see JObject js.lang.JObject is the base class for this */

class BObject()
{
	/* check platform
 	*/
	if (!(System.isIeBrowser()
		|| System.isMozBrowser()
		|| System.isOperaBrowser()))
	{
		throw new NotSupportException("BObject only support IE5+,Moz or Opera!");
	}
	this.uniqueID = BObject.createUniqueId();
}


/**
 * The Unique Id prefix
 * @private
 * @type String */
var uidPrefix = "_jbo_" + new Date().getTime().toString(16) + "_";

/**
 * The Unique Id sequence
 * @private
 * @type String */
var sequence = 0;

/**
 * Create an unique id
 * @param {Object} obj an object
 * @return a Unique Id
 * @type String */
BObject.createUniqueId = function ()
{
	return uidPrefix + (sequence++);
}

/**
 * retrieve an unique id, if has not, create it
 * @return a Unique Id
 * @type String */
BObject.prototype.getUniqueId = function ()
{
	// ie5 not support hasOwnProperty method
	//if (!this.hasOwnProperty("uniqueID"))
	//if (this.uniqueID == null)
	//{
	//this.uniqueID = BObject.createUniqueId();
	//}
	return this.uniqueID;
}

/**
 * the global container
 * @private
 * @type Object */
var container = {};

/**
 * put self into the global container
 * @param {boolean} bool if make self become a globale variable
 */
BObject.prototype.globalize = function (bool)
{
	var uid = this.getUniqueId();
	// put self into the global container
	container[uid] = this;
	// whether become a windows's property
	if (bool == true)
	{
		window[uid] = this;
	}
}

/**
 * un globalize
 */
BObject.prototype.unglobalize = function ()
{
	var uid = this.getUniqueId();
	// remove from the global container
	delete container[uid];
	delete window[uid];
}

/**
 * Retrieve an object by the uniqueID
 * @param {String} sId the uniqueID of object
 * @return an object from container by uniqueID
 * @type Object
 */
BObject.getGlobalObjectByUniqueId = function (sId)
{
	return container[sId];
}

/**
 * Retrieve all objects from the global container
 * @return all objects in the container
 * @type Array
 */
BObject.getAllGlobalObjects = function ()
{
	var objs = [], i = 0;
	for (var uid in container)
	{
		objs[i++] = container[uid];
	}
	return objs;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -