Hi,
I am running into a problem when calling setView(v) method in StatePan where v is a function.
When I call ViewPan.setView(function(){…}) everything works as expected. However, when calling StatePan.setView(function(){…}) it throw a reference error (setView(1) ReferenceError: Method ‘undefined(0)’ not found).
Upon investigating this the “problem” seems to be in:
 

 $template.prototype.$super = function() {
if (pkg.$caller) {
var name = pkg.$caller.methodName,
$s = pkg.$caller.boundTo.$parent,
args = arguments;

if (arguments.length > 0 && typeof arguments[0] === 'function') {
name = arguments[0].methodName;
args = [];
for(var i = 1; i < arguments.length; i++) {
args[i-1] = arguments[i];
}
}

The above code for $super assumes that if the first argument is a function when calling $super method the method name is reestablished via the first argument and the arguments are shifted left. For this reason calling StatePan.setView(function(){…}) fails. I am not sure why there is this restriction.
What if you were to change this as below. This should solve my problem, allowing calling $super with first parameter as a function, and still keep your original intent.

 $template.prototype.$super = function() {
if (pkg.$caller) {
var name = pkg.$caller.methodName,
$s = pkg.$caller.boundTo.$parent,
args = arguments;

if (arguments.length > 0 && typeof arguments[0] === 'function') {
if (typeof arguments[0].methodName== "string") {
name = arguments[0].methodName;

args = [];
for(var i = 1; i < arguments.length; i++) {
args[i-1] = arguments[i];
}
}
}

Thanks.
 

2 answers

Staff February 25, 2016

Sometimes it is necessary to call super of a method from another method. That is why $super checks the first argument to detect if a method has been passed.  I agree the implementation is not good and can bring to situation you have described. Let me think how to fix it (or may be there is no such cases at all where a super method has to be called from another method, so the shift can be removed at all).

#1
Staff February 27, 2016

I have applied fix in next generation of zebra/zebkit  library. Find it on GITHUB in “zebkit-next-generation” branch. The method $super doesn’t check if the first argument is function to shift arguments list. For the execution of super methods from another method “$getSuper(methodName).call(this, arg1 …)” can be used. 

#2

Please login or Register to Submit Answer