In the jstree plugin there is a function like this :
this.check_node = function (obj, e) {
if(this.settings.checkbox.tie_selection) { return this.select_node(obj, false, true, e); }
// Removed code for readability
};
So for the check_node
I have to pass a list of arguments, the list of arguments I have to pass are in an array, so I do as following :
scope.jstree(true).check_node(...scope.args['check_node']);
Where scope.args['check_node']
contains the list of args I want to pass to check_node
, doing this with spread operator won't raise any error, but for a reason I can't work with ES6 syntax and I'm stuck with ES5, so I had to use apply
instead as following :
scope.jstree(true).check_node.apply(null, scope.args['check_node']);
But this will throw the following error :
TypeError: Cannot read property 'settings' of null
which is in this line :
if(this.settings.checkbox.tie_selection)
Why apply in this case is throwing the error and the spread oprator is not ? and how can I solve this ?
Because you're explicitly saying "Make this
during the function call null
" by passing null
as the first argument.
You need to pass the value you want to be this
as the first argument.
I'm not familiar with your library, but this will do it:
var obj = scope.jstree(true);
obj.check_node.apply(obj, scope.args['check_node']);
If jstree
returns scope
, though, you can avoid the variable:
scope.jstree(true).check_node.apply(scope, scope.args['check_node']);