I guess it's much more efficient in javascript to do this.w = 0, the this.setWidth(0), right ? Which means that for performance reasons we are (unfortunately) strongly encouraged to call as less function as possible ?
Apart from the fact that it makes using the api a little more difficult, it makes it harder to automate setting a value by a dictionary that will be used by a function, like the html property. The method is setHTML, and the property is html. If they were following a consistent naming convention like
property -> html
setter -> setHtml
Then we could do something like the following:
DynObject.prototype.takeValuesFromDictionary = function(values) {
var key in values) {
/* This would be a workaround when you want to call a function without relying of an existing naming convention: ex aLayer.takeValuesFromDictionary({setHTML:'test'});
if(typeof(this[key]) == "function") {
this[key](values[key]);
}
else {
*/
var setterName = 'set'+ key.charAt(0).toUpperCase(); + key.slice(1);
if(this[setterName] && typeof(this[setterName] == "function")) {
this[setterName](values[key]);
}
else
this[key] = values[key];
//}
}
}
So the idea is that you first test if an setter exists for this key, and if it does, use it, otherwise affect the instance variable directly.
The big win is on ease of use, and compact code, which means less to download.
Related to this, I wonder what would be the performance of using the watch method on properties that need additional code when set, like html ? It would greatly reduce the use of functions. Does anyone have tried this from a performance point of view ?
Benoit
On Thursday, March 6, 2003, at 12:20 PM, Raymond Irving wrote:
So would you suggest that we keep both methods or just
used the original method?
Any other comments?
--
Raymond Irving
--- Benoit Marchant <[EMAIL PROTECTED]> wrote:
I ran the 2 versions in IE on the mac, creating 2000DynLayer({anchor:{top:0,bottom:0},textSelectable:true});
layers with
speedtest.dynlayer-basic.html. And it looks like the
regular method is
faster, but not all the time. I don't get consistent
results each time.
Benoit
On Wednesday, March 5, 2003, at 09:20 AM, Raymond
Irving wrote:
Hello,to
Benoit had originally suggested that we use a
dictionary object (hash table) to pass parameters
DynLayers but that proved must slower than usinglet
html,x,y,w,h,color. 9I think I've found a way to
the two co-exist:method:
Old way - The original and fastest creation
DynLayer(html,x,y,w,h,bgcolor)methods:
New ways - slower but more flexible creation
DynLayer({html:'Hello',x:100,y:100});
DynLayer({zIndex:2,w:100,h:100});
DynLayer({textSelectable:true});
DynLayer({textSelectable:false,html:'Cool!'});and
DynLayer({x:100,y:100,w:10,h:10,visible:false});
inline layer - when id is set x,y,w,h,bgcolor,z
html will be replaced with values from inline div:file.
DynLayer({id:'myinline'});
DynLayer({id:'boxer',anchor:{left:0:right:0}});
Optional arguments:
x,y,w,h,html,bgColor,zIndex,textSelectable,
anchor,visible,id
Changes are inside the attached dynlayer_ie.js
Please perform all the speed test and improvementsyou
can to see if the new creation method makes anysense
at all.
--
Raymond Irving
__________________________________________________
Do you Yahoo!?
Yahoo! Tax Center - forms, calculators, tips, more
http://taxes.yahoo.com/
__________________________________________________
Do you Yahoo!?
Yahoo! Tax Center - forms, calculators, tips, more
http://taxes.yahoo.com/<dynlayer_ie.zip>
__________________________________________________
Do you Yahoo!?
Yahoo! Tax Center - forms, calculators, tips, more
http://taxes.yahoo.com/
-------------------------------------------------------
This SF.net email is sponsored by: Etnus, makers of TotalView, The debugger
for complex code. Debugging C/C++ programs can leave you feeling lost and
disoriented. TotalView can help you find your way. Available on major UNIX
and Linux platforms. Try it free. www.etnus.com
_______________________________________________
Dynapi-Dev mailing list
[EMAIL PROTECTED]
http://www.mail-archive.com/[EMAIL PROTECTED]/