extending the web is hard
Friday, 6. June 2008, 18:01:03
The wonderful flexibility of ECMAScript / JavaScript lets script authors define nearly anything and everything just about anywhere in the environment. That's why extending JavaScript is getting so complicated - anything we add to specifications and in browsers risks conflicting with something that an author already added somewhere. ES4 plans to come to the rescue with namespaces but until we get there we'll keep stumbling into problems when we try to improve the web. HTML5, you're overdue and welcome - but proceed with caution..










fearphage # 6. June 2008, 21:30
I will be happy to see Opera move beyond js version 1.5.
hallvors # 6. June 2008, 22:40
Me too! These sorts of problems demonstrate why we need ES4 namespaces.
scottj # 7. June 2008, 00:29
scipio # 8. June 2008, 09:14
_Grey_ # 8. June 2008, 14:07
So it's not exactly in the intent of javascript to differentiate between methods and properties.
The problem with replacing "replace" is probably that any function is converted to a string before it is assigned.
You could "fix" this with Getters&Setters to achieve a certain behavior such as "if value passed is a string, use it for WebForms, else use it as normal property".
My implementation is as follows:
function closureMaker(scope,prop){
var oGetr = scope.__lookupGetter__(prop);
var oSetr = scope.__lookupSetter__(prop);
var value, useValue;
function getr(){
if(useValue) return value;
else return oGetr.call(this);
};
function setr(x){
if(typeof x == "string") {
oSetr.call(this,x);
useValue = false;
}
else {
value = x;
useValue = true;
};
};
scope.__defineGetter__(prop,getr);
scope.__defineSetter__(prop,setr);
};
input = document.createElement('input');
closureMaker(input,"replace");
alert(typeof input.replace); //string
input.replace = function(){};
alert(typeof input.replace); //function
alert(new input.replace()); //use function as constructor
input.replace = "value1,value2,value3";
alert(typeof input.replace); //string
This would be a lot easier if Opera exposed the WebForms extensions (e.g. replace) on HTMLInputElement.prototype, though. A simple call like this would suffice:
hallvors # 8. June 2008, 20:53
Um, we don't?? No idea why. Do you know if there is a bug report on this?
_Grey_ # 8. June 2008, 21:51
Well, the latest build I tested here is beta2 of the 9.5 branch, but I believe Opera doesn't, no. I don't believe there is a bug report on this, either.
I don't know the WF2-Interface good enough to tell, but I think it might be related to different "<input type="s having different applicable attributes. Maybe they don't (I really don't know) and this is a valid complaint.
edit: Hmm. Some other properties aren't represented, either. HTMLButtonElement.prototype.type is "undefined" although it should rather be "submit" (imho, unless I'm totally silly). I filed a bug on that a while ago I believe.
xErath # 8. June 2008, 23:31