PDA

View Full Version : UpdateManager.update()



Animal
10 Oct 2006, 4:47 AM
I've just had some extra stuff put in a URL because I've added a function to Object's prototype.

Perhaps



for(key in params){
buf.push(encodeURIComponent(key), '=', encodeURIComponent(params[key]), '&');
}


should be



for(key in params){
if (params.hasOwnProperty(key)){
buf.push(encodeURIComponent(key), '=', encodeURIComponent(params[key]), '&');
}
}


Although, I can see people passing real, functional Objects to have their properties passed back to the server, so possibly:



for(key in params){
if (params.hasOwnProperty(key)){
var v = params[key];
if (typeof v == 'function')
{
if (key.startsWith("get"))
key = key.substr(3);
else if (key.startsWith("is"))
key = key.substr(2);
v = v.call(params);
}
if (typeof v == 'string')
buf.push(encodeURIComponent(key), '=', encodeURIComponent(v), '&');
}
}


where



String.prototype.startsWith = function(prefix)
{
return this.substr(0, prefix.length) == prefix;
}


BTW, just noticed the resizable textbox! Nice one!

jack.slocum
10 Oct 2006, 7:14 AM
There are lots of things going to break if you mess with the Object prototype. Is there any reason that you are? It is generally considered bad practice.

I have to go thru the scripts and find all for...in loops and clear this up for the next release.

Animal
10 Oct 2006, 7:39 AM
I've added an isInstanceOf() method which goes up the superclass chain created by YAHOO.extend()

That way, I can check if any container passed to my AspicioList constructor to hold the list is an instance of YAHOO.widget.Panel. It will probably be a subclass, but if it's a Panel, I know to create the container Element from its body property. If it's not, then it might be an Element, an HTMLElement, or a String id, so I can create the container Element directly.

I suppose it should just be a static method "isInstanceOf(obj, class)" rather than a method of Object, but it seems like it should be there!

jack.slocum
10 Oct 2006, 7:44 AM
I agree instanceOf should be there. I once created one myself and got rid of it quickly. Instead I use:

Object.instanceOf = function(obj, targetClass){...}

The couple additional keystrokes to keep default object literals intact was worth it IMO.