T
Thomas 'PointedEars' Lahn
dhtml said:What design patterns in Mootools were criticized?
I am not here to reiterate this discussion for you.
Take the pageX/Y properties. Problems in Firefox were that it did not
include scroll. An experimental monkey patch:-
MouseEvent.prototype.__defineGetter__('pageX', function() {
return this.clientX + window.pageXOffset;
});
MouseEvent.prototype.__defineGetter__('pageY', function() {
return this.clientY + window.pageYOffset;
});
If the monkey patch worked, it could be later incorporated into a real
patch.
Nobody in their right mind would write or test *Gecko* patches like so.
You will have to come up with something more convincing.
Many DOM properties have a |readonly| flag. This flag can map to
ECMAScript {ReadOnly} attribute. However, there is nothing that maps to
ECMAScript {DontEnum} attribute. This is not defined for any dom
objects,
That might sound highly sophisticated to some, but is utter nonsense altogether.
The ECMAScript `ReadOnly' attribute of properties applies for native objects
only because only those objects MUST implement the internal [[Put]] method
as specified where [[CanPut]] is called and the ReadOnly property becomes
relevant in the first place. In fact, it can be readily observed that
assigning to a property which is "readonly" per the IDL or the
implementation, reverts back in some implementations to its previous value
instead of just not being modified, and that the assignment can result in a
runtime error, which is also not specified at all in ECMAScript. (We have
discussed this ad nauseam here.)
The ECMAScript `DontEnum' attribute of properties does not apply to
properties of host objects per Specification, however it can be readily
observed that some properties of host objects do not occur in a for..in
iteration. (We have discussed this ad nauseam here as well.)
and so it is entirely dependent on the implementation.
We have a property of a host object here that is deliberately exposed by the
implementor, and it refers to a native object. It provides an efficient
means to add new default properties and new methods to a certain class of
related host objects. Not to use it and use another, less efficient
approach instead, is foolish.
The Host object might have a property with the same name hidden away
somewhere else on the object or its prototype chain. It might have a
getter defined on that object itself.
It would not, else the object the property refers to would either be made
non-augmentable (which is possible with host objects only) or the property
would not be publicly exposed by the implementation at all.
If('
Pardon?
The design issue...
Pardon?
I don't have costly iteration in my scripts and I never augment
Element.prototype. It is a solution to a problem that does not exist.
To a problem that *you* do not have. At least one OP had this problem
already, and I can imagine situations where this feature comes in handy.
"Big ball of mud" is packaging of everything together. ["snipped ball of
mud" "explanation"]
Sounds like a big ball of mud altogether.
I see no good reason why not to make use of such a useful DOMfeature if it is available. (In fact, I think it has the capacity to
become a DOM standard.)
It is becoming a DOM standard (WEB IDL). [...]
URL?
An element object reference, and the greater efficiency in this case
would seem to be self-evident.
As always, the bargain is runtime efficiency vs. memory efficiency.
Comparing:-
// 1.
Element.prototype.getX = function() { };
// 2.
function getX(el) { }
Where is the memory efficiency in #1?
If getX() is empty, none.
Function getX (2) would not have to be resolved off the host object's
prototype chain.
True, but if getX() was not empty, you would need to pass the element as an
argument, check the argument type, determine which class of element object
was being referred to with the passed value aso.
Element.prototype.getX would have to be resolved up the prototype chain.
We have discussed the efficiency of the prototype chain already.
The prototype chain in this particular case could not be shorter:
Element instance --> Element.prototype --> Node.prototype
--> Object.prototype --> null
The expected loss in runtime efficiency by using it is thus negligible.
That said, this is a border case. One would seldom want to augment
Element.prototype.
Given a host object Element, Element.prototype does not have to be a
native object.
True, but it is a native object in the relevant implementations.
Consider a case of a hypothetical user-defined property |x| on
Element.prototype, Element.prototype.x. When resolving an identifier |x|
on an img object, img.x, the |x| property would be not be resolved on
Element.prototype. Instead, it would more likely be found in
HTMLImageElement.prototype, or on the object itself. The |x| property
might be implemented as a getter or it might be implemented as a property.
Node
|
Element {x:Function(user-def} EventTarget
| |
HTMLElement {style::ElementCSSInlineStyle}
|
HTMLImageElement { getter x::uint }
|
img
[...]
You are constantly ignoring the fact that e.g. HTMLImageElement.prototype
could be augmented as well, and the benefit that could bring. You must do
so because otherwise you would hurt the pointless argument which says that
using host object's prototypes is a bad idea per se.
PointedEars