On Aug 12, 1:56 am, kangax <
kan...@gmail.com> wrote:
> On Aug 11, 11:15 am, Tobie Langel <
tobie.lan...@gmail.com> wrote:
>
> > JDD, Rob, here's why ...invoke('removeAttribute', 'id'); wouldn't
> > work.
>
> > As you know, invoke relies on the apply method of function instances:
>
> > invoke: function(method) {
> > var args = $A(arguments).slice(1);
> > return this.map(function(value) {
> > return value[method].apply(value, args);
> > });
> > },
>
> > Unfortunately, IE doesn't grant all DOM methods a full function
> > status. Methods such as (get/set/remove)Attribute are deprived of call/
> > apply methods.
>
> > For a quick test, just try the following in IE:
http://gist.github.com/4867
A simpler, though probably less conclusive, test is:
alert( typeof element.removeAttribute.apply ) // undefined in IE
> > Hence the need to use the writeAttribute proxy.
That is one way, another is to use each instead of invoke to call host
methods.
> I'm not sure why, but certain native host methods are not overwritten
> in IE (when extending an element):
There is no guarantee that you will be able to overwrite host
properties in the future, the proposed ECMA-262 ed4 spec makes it a
problematic exercise for native objects, there are many places where
it says things like:
"The new properties are visible to “in” and “hasOwnProperty” tests.
They are all DontDelete, typed, and in some cases ReadOnly, and
user programs cannot generally use them for anything other than
their intended purpose."
It will be interesting to see the extent that host objects are
similarly "improved". I seem to remember that Mozilla was going to do
the same with some host methods for security reasons, I can't find a
reference (it might have been to ES4...).
> Is this a bug or was it done intentionally?
>
> ...
> if (Object.isFunction(value) && !(property in element))
> element[property] = value.methodize();
> ...
> "!(property in element)" is what makes Element.extend skip the
> properties.
I don't think so, the test is never reached in IE - its host methods
will return false from isFunction (which is why I think having an
isFunction function is not a good idea). If the use of isFunction is
to determine if the object has call or apply methods, they should be
tested explicitly and the function called 'hasCall' or 'hasApply'.
This goes to the heart of inferring certain properties by testing some
other property (i.e. testing if typeof returns function to infer that
the object has call or apply methods).
> #focus and #select (and maybe others) are not replaced with Prototype
> "alternatives", resulting in failure to call `invoke` and returning
> `undefined` rather than an element-receiver.
Use each instead. For the original example and borrowing from Tobie's
code:
$(clone).select('*[id]').concat(clone).each(
function(n){n.removeAttribute('id');}
);
presuming that the IDs really did need to be removed, it is more
likely that they need to be modified to make them unique (otherwise
why did they have IDs in the first place?). Of course that is up to
the OP. :-)
--
Rob