I am importing javascript like below
var imported = document.createElement('script');
imported.src = 'script.js';
document.head.appendChild(imported);
In my script.js I have following code
Array.prototype.hasMin = function (attrib) {
return (
(this.length &&
this.reduce(function (prev, curr) {
return prev[attrib] < curr[attrib] ? prev : curr;
})) ||
null
);
};
When i Just use the above code in script tag its working normally , but when i use it via appendchild method , I get following error
Uncaught Error: Syntax error, unrecognized expression: #function (attrib) {