12-20-2019 14:08
12-20-2019 14:08
Hello,
I've built a first version of my clockface with the 4.0 SDK recently and I was using classes with prototypes and I updated to the 4.1 SDK 3 days ago and for some reasons I can't compile anymore.
I get " App: Unhandled exception: TypeError: Expected a function. " whenever I try to call a prototype function in my classes.
Does anyone have any ideas as to why this is happening ?
Answered! Go to the Best Answer.
12-28-2019 08:34
12-28-2019 08:34
Ok, I've figured it out.
Basically it's my fault, I was calling the "this" keyword inside another class that did not have the method I was trying to execute. The call was mixed up inside a class that add a single call to a system class which explains the mix up !
Eveything is working fine now !
12-21-2019 07:05
12-21-2019 07:05
Do you have some code that worked before which now doesn't we could look at? It's hard to help without specifics unfortunately.
12-21-2019 13:42
12-21-2019 13:42
Yes sure :
Here's a sample class that used to work and does not anymore :
export function RetroSettings(){
this.settings_type = "json";
this.settings_file = "settings.json";
}
RetroSettings.prototype.load = function() {
this.settings = this.loadSettings();
//console.log(`Settings loaded : ${JSON.stringify(this.settings.classe)}`);
this.applyTheme(this.settings.background, this.settings.foreground);
this.applyCharacter(this.settings.classe);
this.applyClockSize(this.settings.size);
// Listen for the onmessage event
messaging.peerSocket.onmessage = evt => {
//console.log(`App received: ${JSON.stringify(evt.data)}`);
if(evt.data.classe){
this.applyCharacter(evt.data.classe);
}
if(evt.data.background && evt.data.foreground){
this.applyTheme(evt.data.background, evt.data.foreground);
}
if(evt.data.size){
this.applyClockSize(evt.data.size);
}
};
// Register for the unload event
appbit.onunload = this.saveSettings;
};
The loadSettings method throws this error now :
App: Unhandled exception: TypeError: Expected a function. ? at app/retro/RetroSettings.js:28,1
This is just and example but every prototype methods throw this error now.
Works on SDK 4.0 but not 4.1
12-23-2019 03:22
12-23-2019 03:22
Is that the whole file? Just trying to figure out which line the error refers to.
12-23-2019 03:25
12-23-2019 03:25
I just tried this code in both SDK 4.0 and SDK 4.1 and saw both log messages with no errors:
function MyClass() {
console.log('ctor');
}
MyClass.prototype.load = function() {
console.log('load');
}
const mc = new MyClass();
mc.load();
So I think your example in isolation perhaps isn't enough to reproduce whatever the issue is.
12-26-2019 04:26
12-26-2019 04:26
Hi,
I'm wondering if it comes from the "this" keyword inside the class itself for some reason.
Calling the method outside works but calling it from inside the class does not...
Weird...
12-28-2019 08:34
12-28-2019 08:34
Ok, I've figured it out.
Basically it's my fault, I was calling the "this" keyword inside another class that did not have the method I was trying to execute. The call was mixed up inside a class that add a single call to a system class which explains the mix up !
Eveything is working fine now !