1 //<script type="text/javascript">
4 * Similar to Prototype / jQuery API
5 * implements standard object/class constructor tools
11 //imports['Object.js'].load(Object);
15 load = false; // declare global for gnome langs.
22 * Copies all the properties of config to obj.
24 * Pretty much the same as JQuery/Prototype..
25 * @param {Object} obj The receiver of the properties
26 * @param {Object} config The source of the properties
27 * @param {Object} defaults A different object that will also be applied for default values
28 * @return {Object} returns obj
29 * @member Object extend
33 extend : function(o, c, defaults){
35 // no "this" reference for friendly out of scope calls
36 Object.extend(o, defaults);
38 if(o && c && typeof c == 'object'){
48 * Copies all the properties of config to obj, if the do not exist.
49 * @param {Object} obj The receiver of the properties
50 * @param {Object} config The source of the properties
51 * @return {Object} returns obj
52 * @member Object extendIf
56 extendIf : function(o, c){
58 if(!o || !c || typeof c != 'object'){
62 if (typeof(o[p]) != 'undefined') {
72 * Extends one class with another class and optionally overrides members with the passed literal. This class
73 * also adds the function "override()" to the class that can be used to override
74 * members on an instance.
77 * MyObject = Object.define(
81 * parentClass, // or Object
83 * ... methods and properties.
86 * @param {Function} constructor The class inheriting the functionality
87 * @param {Object} superclass The class being extended
88 * @param {Object} overrides (optional) A literal with members
89 * @return {Function} constructor (eg. class
99 return function(sb, sp, overrides) {
100 if (typeof(sp) == 'undefined') {
101 // error condition - try and dump..
102 throw "Missing superclass: when applying: " + sb
105 var F = function(){}, sbp, spp = sp.prototype;
107 sbp = sb.prototype = new F();
112 if(spp.constructor == Object.prototype.constructor){
116 sb.override = function(o){
117 Object.extend(sb.prototype, o);
120 Object.extend(sb.prototype, overrides);
127 * returns a list of keys of the object.
128 * @param {Object} obj object to inspect
129 * @return {Array} returns list of kyes
130 * @member Object keys
146 load = function(ar) {
148 imports.lang.copyPropertiesNoOverwrite( object,ar);
152 // non imports version.
156 Object[i] = object[i];