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.
Best AnswerOk, 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 !
Best Answer
Fitbit Developers oversee the SDK and API forums. We're here to answer questions about Fitbit developer tools, assist with projects, and make sure your voice is heard by the development team.
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
Best Answer
Fitbit Developers oversee the SDK and API forums. We're here to answer questions about Fitbit developer tools, assist with projects, and make sure your voice is heard by the development team.
Is that the whole file? Just trying to figure out which line the error refers to.
Best Answer
Fitbit Developers oversee the SDK and API forums. We're here to answer questions about Fitbit developer tools, assist with projects, and make sure your voice is heard by the development team.
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.
Best AnswerHi,
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...
Best AnswerOk, 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 !
Best Answer