Re: Deprecated Attr methods

I'm not quite following, how are you setting the attribute name (not
value) to "[foo]"? All ways of attempting to set the attribute name to
"[foo]" should throw an exception, and AFAICT this is not related to
the deprecated aspects of the Attr interface.

On Fri, May 22, 2015 at 4:33 PM, Matthew Phillips <matthew@bitovi.com> wrote:
> I spoke too soon, that workaround won't work for the same reason
> setAttribute will not.
>
> On Fri, May 22, 2015 at 10:30 AM, Matthew Phillips <matthew@bitovi.com>
> wrote:
>>
>> Thanks Philip.  setAttribute can't be used in my scenario because it
>> doesn't accept some characters, this will throw:
>>
>> el.setAttribute("[foo]", "bar")
>>
>> As not being a valid attribute name. However innerHTML will accept these
>> types of attribute names just fine.
>>
>> These special attribute names are started to be adopted by frameworks for
>> data-binding (Angular 2 is doing something like this I believe).
>>
>> Maybe we should adjust what is a valid attribute name?
>>
>> For now I think your workaround might work, I'll give it a try.
>>
>> On Fri, May 22, 2015 at 8:14 AM, Philip Jägenstedt <philipj@opera.com>
>> wrote:
>>>
>>> On Thu, May 21, 2015 at 8:01 PM, Matthew Phillips <matthew@bitovi.com>
>>> wrote:
>>> > I just came across a warning for using a deprecated Attr method:
>>> >
>>> >
>>> > https://developer.mozilla.org/en-US/docs/Web/API/Attr#Deprecated_properties_and_methods
>>> >
>>> > I'm using cloneNode() which is on the list. What is the workaround?
>>> > Will I
>>> > be able to do Node.prototype.cloneNode.call(attr) instead?
>>>
>>> Hi Matthew,
>>>
>>> This is related to a simplification of Attr that, if successful, would
>>> result in Attr no longer inheriting from Node:
>>> https://dom.spec.whatwg.org/#interface-attr
>>>
>>> If that happens, Node.prototype.cloneNode.call(attr) wouldn't work
>>> either, because attr would no longer be a Node, so it would throw an
>>> exception.
>>>
>>> Your best bet is to avoid Attr entirely, using getAttribute() and
>>> setAttribute() instead. However, if for some reason you have an Attr
>>> and want to set the same attribute on another element,
>>> element2.setAttributeNS(attr.namespaceURI, attr.name, attr.value)
>>> should do the trick.
>>>
>>> Philip (does not work on Gecko, but pokes at Attr in Blink)
>>
>>
>>
>>
>> --
>> Bitovi
>> Development | Design | Training | Open Source
>
>
>
>
> --
> Bitovi
> Development | Design | Training | Open Source

Received on Monday, 25 May 2015 08:30:17 UTC