I have js code that needs to be translatable to Dart:
(function() {
var s, e;
s = document.createElement("script");
s.src = “//someurl.com/somefile.js";
s.async = true;
e = document.getElementsByTagName("head")[0];
e.insertBefore(s, e.firstChild);
this.OBJECT = this.OBJECT || {};
this.OBJECT.array = this.OBJECT.somearray || [];
})();
OBJECT.somearray.push({
val1 : “foo",
val2 : “bar"
});
Basic part to embed script into head I did like this:
ScriptElement scr = new ScriptElement()
..src = "//someurl.com/somefile.js";
..async = true;
querySelector('head').append(scr);
But I don't know how to correctly check if OBJECT and OBJECT.somearray exists in somefile.js and push an object item in it.
With dart:js you can check the presence of a global variable with :