Closed midudev closed 2 years ago
node.data('score')
equals node.data.score
So, whats the difference between node.data.score
and node.score
?
Actually, under the hood, there's a lot more done than this. You can take a look to the documentation of Cheerio for readData, setData and data: https://github.com/cheeriojs/cheerio/blob/master/lib/api/attributes.js
It does some unnecessary checks for our intentions, loop, store data on a internal cache, ...
I would say that kind of methods are intended to manipulate HTML5 data-attributes, which is great, but in that specific case (that's not being used here for that intention) could be simplified to a fastest access by simply giving to the node a new property.
It makes sense :)
After done some research I'm looking about node.data(). Would it be a good idea to extend the node element object with a property
score
instead using the DOM to store the score and grab it again using Cheerio?From my understanding I see some benefits:
node.score
vs. `node.data('scoreKey')What do you think @Tjatse?