문제

In E4X I can add an element to another element either via an E4X operator or method:

// operator
var errorXml = <error></error>;
reportXml.errors.error += errorXml;

// method
var errorXml = new XML('<error></error>');
reportXml.errors.appendChild(errorXml);

I know I can add an attribute to my errorXml element using the @ operator:

errorXml.@description = 'uh oh!';

But how can I achieve the equivalent to that using an E4X method? Is it even possible? I'm after this because I'm attempting to write JavaScript that will successfully pass JSHint linting.

도움이 되었습니까?

해결책

Looking through http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-357.pdf I couldn't find a method that would suit.

In your example you are just setting the description attribute. A way that would pass linting for that specific example would be:

var desc = 'uh-oh';   
var errorXml = new XML('<error description=\"' + desc + '\"></error>');
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top