Read the statement by Michael Teeuw here.
Access the default values in outside functions
-
I’m having troubles accessing my default values in my hello function, in my start function the values exist but in hello they are undefined and unreadable, code is below:
Module.register("jarvis", { // Module defaults defaults: { assistantName: "jarvis", assistantVoice: "UK English Male" }, // Required Scripts getScripts: function() { return ["annyang.js", "http://code.responsivevoice.org/responsivevoice.js"]; }, hello: function(name) { if(name) name = name.trim().toLowerCase(); Log.info(name) Log.info(this.config.assistantName) if(name && (name == this.config.assistantName)) responsiveVoice.speak("Hello George"); else { responsiveVoice.speak("Hello"); } }, start: function() { Log.info("Starting module: " + this.name); annyang.debug(); if (annyang) { // Let's define a command. var commands = { 'hello (*name)': this.hello }; // Add our commands to annyang annyang.addCommands(commands); // Start listening. annyang.start(); } Log.info(this.config.assistantVoice) Log.info(this.config.assistantName) // Setting voice default responsiveVoice.setDefaultVoice(this.config.assistantVoice); } });Please help, thank you!
-
That’s because “this” is no longer referring to your instance. It’s a common javascript pitfall. Check out:
http://javascriptplayground.com/blog/2012/04/javascript-variable-scope-this/ -
@MichMich Oh okay, thanks for the help!
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login