I see some use:
var dom = document.getElementById('id');
var myChart = echarts.init(dom);
and others:
myChart = echarts.init(document.getElementById('id'));
Is one preferable for some reason or is it just a matter of choice? I prefer the second as it saves a line of code
2
Answers
I think this is a personal preference. Some folks may find it preferable to explicitly declare a variable to get the document’s id. And another to initialize the charts.
One thing I will mention is that using
var
is falling out of flavor in post ES6, in favor oflet
orconst
.I would suggest using a
const
to store the DOM Element for later, as you are already getting it and you might need it later, if you don’t, you could always revert to the original method of getting the DOM Element within the args of the function.If you even might need to use the element later
If you know you don’t need the element again