I have the following problem I have an array that adds the instance of an auxiliary object to the instance of an HTMLElement, but only the last element is being added, I tested it in the Chrome, Chromium, Opera and Mozilla Firefox browser and in none of them presented a different result.
This is the code in CoffeeScript adding the instance to the array:
array = []
if not isEmpty(results)
for result in results
element = new VanillaHTMLDOMElement(result)
console.log(element.getAttribute('id')) ##imprime o id do elemento normalmente
array.push(element)
for item in array
console.log item.getAttribute('id') ##imprime nulo para todos os casos
return array
This is the JavaScript code by adding the instance in the array:
var array, element, item, result, _i, _j, _len, _len1;
array = [];
if (!isEmpty(results)) {
for (_i = 0, _len = results.length; _i < _len; _i++) {
result = results[_i];
element = new VanillaHTMLDOMElement(result);
console.log(element.getAttribute('id')); //imprime o id do elemento normalmente
array.push(element);
}
}
for (_j = 0, _len1 = array.length; _j < _len1; _j++) {
item = array[_j];
console.log(item.getAttribute('id')); //imprime nulo para todos os casos
return array
}
return array;
I think it's due to some form of Asynchronism, but I would like to confirm it and would like to know if anyone knows a solution?