Changeset 7988
- Timestamp:
- 04/07/07 15:51:40 (20 months ago)
- Location:
- dojo/trunk
- Files:
-
- 3 added
- 6 modified
-
tests/_base.js (modified) (1 diff)
-
tests/_base/connect.js (added)
-
tests/_base/declare.js (modified) (1 diff)
-
_base.js (modified) (1 diff)
-
_base/connect.js (added)
-
_base/declare.js (modified) (5 diffs)
-
_base/event.js (added)
-
_base/lang.js (modified) (4 diffs)
-
_base/_loader/bootstrap.js (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
dojo/trunk/tests/_base.js
r7973 r7988 119 119 dojo.require("tests._base.lang"); 120 120 dojo.require("tests._base.declare"); 121 dojo.require("tests._base.connect"); 121 122 dojo.require("tests._base.Deferred"); 122 123 dojo.require("tests._base.json"); -
dojo/trunk/tests/_base/declare.js
r7917 r7988 161 161 }, 162 162 baz: function(arg1, arg2){ 163 this.inherited("bar", arguments); 163 //this.inherited("baz", arguments); 164 this.inherited("bar", arguments, tests._base.declare.tmp15.prototype.bar); 164 165 } 165 166 } -
dojo/trunk/_base.js
r7980 r7988 1 1 dojo.require("dojo._base.lang"); 2 2 dojo.require("dojo._base.declare"); 3 dojo.require("dojo._base.connect"); 3 4 dojo.require("dojo._base.Deferred"); 4 5 dojo.require("dojo._base.json"); 5 6 dojo.require("dojo._base.array"); 6 7 // dojo.requireIf(dojo.isBrowser, "dojo._base.browserConnect"); 7 // dojo.requireIf(dojo, "dojo._base.connect");8 dojo.requireIf(dojo.isBrowser, "dojo._base.event"); 8 9 dojo.requireIf(dojo.isBrowser, "dojo._base.html"); 9 10 dojo.requireIf(dojo.isBrowser, "dojo._base.NodeList"); -
dojo/trunk/_base/declare.js
r7917 r7988 27 27 // prototype extension. 28 28 // 29 // All "superclass(es)" must be Functions (not mere Objects).29 // All superclasses (including mixins) must be Functions (not simple Objects). 30 30 // 31 31 // Mixin ancestors provide a type of multiple inheritance. 32 // The prototypical properties of mixin ancestors are copied33 // to the subclass.32 // 33 // Prototypes of mixin ancestors are copied to the new class. 34 34 // 35 // name of the class ("className" argument) is stored in 36 // "declaredClass" property 37 // 38 // Aliased as "dojo.declare" 35 // "className" is cached in "declaredClass" property of the new class. 39 36 // 40 37 // usage: … … 87 84 ctor.mixins = mixins; 88 85 // copy the mixin prototype to the new prototype 89 dojo.forEach(mixins, function(i){ 90 dojo.extend(ctor, i.prototype); 91 }); 92 /* 93 for(var i=0,l=mixins.length; i<l; i++){ 94 dojo.extend(ctor, mixins[i].prototype); 86 for(var i=0,m;(m=mixins[i]);i++){ 87 dojo.extend(ctor, m.prototype); 95 88 } 96 */97 89 // 98 90 // V. Finalize constructor … … 111 103 // 112 104 // VI. Create named reference 113 // with(dojo.getProp(className, true)){obj[prop] = ctor;} 114 var pcn = className.split("."); var oname = pcn.pop(); pcn = pcn.join("."); 115 var prt = (pcn.length) ? dojo.getObject(pcn, true) : dojo.global(); 116 prt[oname] = ctor; 117 return ctor; // Function 105 return dojo.setObject(className, ctor); // Function 118 106 } 119 107 … … 125 113 // initialize any mixins 126 114 if(c.mixins){ 127 // FIXME: why mp?128 for(var i=0, m, mp; (m=c.mixins[i])&&(mp=m.prototype); i++){129 ( mp.initializer||m).apply(this, arguments);115 for(var i=0, m, f; (m=c.mixins[i]); i++){ 116 // avoid the constructor on 'declared' mixins 117 (f=("initializer" in m ? m.initializer : m))&&(f.apply(this, arguments)); 130 118 } 131 119 } … … 140 128 _findInherited: function(name, callee){ 141 129 var p = this.constructor.prototype; 142 var lp; 143 if(this[name] !== callee){ 144 while(p && (p[name] !== callee)){ 145 lp = p; 146 p = p.constructor.superclass; 130 if (this[name]!==callee){ 131 while(p && (p[name]!==callee)){ 132 p = p.constructor.superclass; 147 133 } 148 p = lp;149 134 } 150 while(p && (p[name] === callee)){151 p = p.constructor.superclass;135 if ((!p)||(p[name]!==callee)){ 136 throw(this.toString() + ': name argument ("' + name + '") to inherited does not match callee (declare.js)'); 152 137 } 153 return (p)&&(p[name]); 138 while(p && (p[name]===callee)){ 139 p = p.constructor.superclass; 140 } 141 return (p)&&(p[name]); 154 142 }, 155 143 inherited: function(name, args, callee){ -
dojo/trunk/_base/lang.js
r7917 r7988 5 5 dojo.isString = function(/*anything*/ it){ 6 6 // summary: Return true if it is a String. 7 8 return (typeof it == "string" || it instanceof String); 7 return (typeof it == "string" || it instanceof String); // Boolean 9 8 } 10 9 11 10 dojo.isArray = function(/*anything*/ it){ 12 11 // summary: Return true of it is an Array 13 14 12 return (it && it instanceof Array || typeof it == "array" || ((typeof dojo["NodeList"] != "undefined") && (it instanceof dojo.NodeList))); // Boolean 15 13 } … … 72 70 } 73 71 // IE doesn't recognize custom toStrings in for..in 74 if( dojo.isIE &&72 if(dojo.isIE && 75 73 (typeof(props["toString"]) == "function") && 76 74 (props["toString"] != obj["toString"]) && … … 101 99 } 102 100 103 dojo.hitch = function(/*Object*/thisObject, /*Function|String*/method /*, ...*/){ 101 dojo._hitchArgs = function(scope, method /*,...*/){ 102 var pre = []; 103 for(var x=2; x<arguments.length; x++){ 104 pre.push(arguments[x]); 105 } 106 var named = dojo.isString(method); 107 return function(){ 108 // arrayify arguments 109 var args = []; 110 for(var x=0; x<arguments.length; x++){ 111 args.push(arguments[x]); 112 } 113 // locate our method 114 var f = (named ? (scope||dojo.global())[method] : method); 115 // invoke with collected args 116 return (f)&&(f.apply(scope||this, pre.concat(args))); // Any 117 } // Function 118 } 119 120 dojo.hitch = function(/*Object*/scope, /*Function|String*/method /*,...*/){ 104 121 // summary: 105 // Returns a function that will only ever execute in the a given scope 106 // (thisObject).This allows for easy use of object member functions122 // Returns a function that will only ever execute in the a given scope. 123 // This allows for easy use of object member functions 107 124 // in callbacks and other places in which the "this" keyword may 108 // otherwise not reference the expected scope. Any number of default 109 // positional arguments may be passed as parameters beyond "method". 125 // otherwise not reference the expected scope. 126 // Any number of default positional arguments may be passed as parameters 127 // beyond "method". 110 128 // Each of these values will be used to "placehold" (similar to curry) 111 // for the hitched function. Note that the order of arguments may be112 // reversed in a future version.113 // thisObject: the scope to run the method in129 // for the hitched function. 130 // scope: 131 // The scope to run the method in 114 132 // method: 115 // a function to be "bound" to thisObjector the name of the method in116 // thisObject to be used as the basis for the binding133 // A function to be hitched to scope, or the name of the method in 134 // scope to be hitched. 117 135 // usage: 118 136 // dojo.hitch(foo, "bar")(); // runs foo.bar() in the scope of foo 119 137 // dojo.hitch(foo, myFunction); // returns a function that runs myFunction in the scope of foo 120 121 // FIXME:122 // should this be extended to "fixate" arguments in a manner similar123 // to dojo.curry, but without the default execution of curry()?124 var args = [];125 for(var x=2; x<arguments.length; x++){126 args.push(arguments[x]);138 if(arguments.length > 2){ 139 return dojo._hitchArgs.apply(dojo, arguments); 140 }else if(dojo.isString(method)){ 141 scope = scope || dojo.global(); 142 return function(){ return scope[method].apply(scope, arguments||[]); } 143 }else{ 144 return (!scope ? method : function(){ return method.apply(scope, arguments||[]); }); 127 145 } 128 var fcn = ((dojo.isString(method)) ? (thisObject||dojo.global())[method] : method) || function(){};129 return function(){130 var ta = args.concat([]); // make a copy131 for(var x=0; x<arguments.length; x++){132 ta.push(arguments[x]);133 }134 return fcn.apply((thisObject||this), ta); // Function135 };136 146 } 137 147 … … 152 162 // whatever the execution context eventually becomes. This is the 153 163 // functional equivalent of calling: 154 // dojo.hitch(null, funcName, ...);164 // dojo.hitch(null, funcName, ...); 155 165 var args = [ null ]; 156 166 for(var x=0; x<arguments.length; x++){ -
dojo/trunk/_base/_loader/bootstrap.js
r7774 r7988 99 99 } 100 100 101 dojo.getObject = function(/*String*/name, /*Boolean*/create, /*Object*/obj){ 102 // summary: 103 // gets an object from a dot-separated string, such as "A.B.C" 101 dojo._getProp = function(/*Array*/parts, /*Boolean*/create, /*Object*/context){ 102 var obj=context||dojo.global(); 103 for(var i=0, p; obj&&(p=parts[i]); i++){ 104 obj = (p in obj ? obj[p] : (create ? obj[p]={} : undefined)); 105 } 106 return obj; // Any 107 } 108 109 dojo.setObject = function(/*String*/name, /*Any*/value, /*Object*/context){ 110 // summary: 111 // Set a property from a dot-separated string, such as "A.B.C" 104 112 // description: 105 // useful for longer api chains where you have to test each object in 106 // the chain 113 // Useful for longer api chains where you have to test each object in 114 // the chain, or when you have an object reference in string format. 115 // Objects are created as needed along 'path'. 107 116 // name: 108 // Path to an object, in the form "A.B.C". 109 // obj: 117 // Path to a property, in the form "A.B.C". 118 // context: 119 // Optional. Object to use as root of path. Defaults to 120 // 'dojo.global()'. Null may be passed. 121 var parts=name.split("."), p=parts.pop(), obj=dojo._getProp(parts, true, context); 122 return (obj && p ? (obj[p]=value) : undefined); // Any 123 } 124 125 dojo.getObject = function(/*String*/name, /*Boolean*/create, /*Object*/context){ 126 // summary: 127 // Get a property from a dot-separated string, such as "A.B.C" 128 // description: 129 // Useful for longer api chains where you have to test each object in 130 // the chain, or when you have an object reference in string format. 131 // name: 132 // Path to an property, in the form "A.B.C". 133 // context: 110 134 // Optional. Object to use as root of path. Defaults to 111 135 // 'dojo.global()'. Null may be passed. … … 113 137 // Optional. If true, Objects will be created at any point along the 114 138 // 'path' that is undefined. 115 var tprop, tobj = obj||dojo.global(); 116 var parts=name.split("."), i=0, lobj, tmp, tname; 117 do{ 118 lobj = tobj; 119 tname = parts[i]; 120 tmp = tobj[parts[i]]; 121 if((create)&&(!tmp)){ 122 tmp = tobj[parts[i]] = {}; 123 } 124 tobj = tmp; 125 i++; 126 }while(i<parts.length && tobj); 127 return tobj; // Object 139 return dojo._getProp(name.split("."), create, context); // Any 128 140 } 129 141 … … 139 151 // Optional. Object to use as root of path. Defaults to 140 152 // 'dojo.global()'. Null may be passed. 141 return (!!dojo.getObject(name, false, obj)); // Boolean153 return Boolean(dojo.getObject(name, false, obj)); // Boolean 142 154 } 143 155