Open Konubinix opened 4 years ago
Good question! The trouble with node-list objects is that they do not behave properly as arrays and their behavior may depend per browser. Auto-converting to an array is an option, but adding a test at every for-loop to check whether the iterate is a nodelist is expensive ... That's why it's as it is now.
I could imagine that a user could explicitly cast it to a list somehow. Maybe just with list()
? In PScript we'd then have to do the check when list()
is called.
I don't know whether this is the good place to make this request.
Using flexx to create an application, I from time to time need to find all the elements inside a node. I wish I could write the following
for element in self.node.querySelectorAll("a"): ...
. Unfortunately, this iteration assigns the indexes into element (1, 2, 3...), then I need to write the code asThis does not feel very pythonic.
IIUC, the transpiling happens in Parser2._make_iterable, the iteration is converted in
I don't know how NodeList could be taken into account here, I guess that ideally, the condition isArray could be extended to find out other known types that can coerce to Array
if(NodeList.prototype.isPrototypeOf(stub1_seq)){stub1_seq = Array.from(stub1_seq);}
. I don't know of a more generic way of doing. I python, I would do something like :