When writing a script I encountered such a problem: In the below attached fragment of the simplified code in which I will mark the desired section, when I call through apply() , an error appears on the second pass:
Uncaught TypeError: CreateListFromArrayLike called on non-object That is, the first time it works correctly. And in the second pass an error occurs, even before entering the function. At the same time, if apply() replaced by call() , then everything starts working correctly. Perhaps I do not fully understand the difference in these methods. It seems the only difference is in the dynamic range of the apply() arguments. Although maybe I'm confusing something.
I would be glad if I was explained the reason for this behavior. Here is the whole code. Thank you in advance.
function MetaRow(name,value){ this.name = name; this.value = value; } function MetaGroup(name){ this.name = name; this.items = {}; this.groups = {}; } MetaGroup.prototype.set = function(key,meta,replace = false) { if(meta instanceof MetaRow){ //Добавляем строку } else if(meta instanceof MetaGroup){ //Добавляем группу } } function FormMeta(forms) { this.forms = forms; this.Global = new MetaGroup(); FormMeta.prototype.update.apply(this); } FormMeta.prototype.get = function(key) { return this.Global.groups[key] != undefined ? this.Global.groups[key] : this.Global.groups['main']; } FormMeta.prototype.pickRadio = function(form) { var glob = this; $(form).find('radio-group').each(function(i,val){ var targetGroup,mid,rid,rname; //Далее я заполняю переменные ничего интересного //Вот на это строке в момент вызова apply() генерируется ошибка FormMeta.prototype.get.apply(glob,mid).set(rid, new MetaRow(rname),true); })