I need someone good at javascript, because I’m facing a nice difficulty… :

I need someone good at javascript, because I’m facing a nice difficulty… :

For my TaskerTask API, I have the object TaskerTask which has a var. The TaskerTask constructor is like : 

function TaskerTask() {

    var intent = new TaskerIntent();

}

Now, I have functions like :

TaskerTask.prototype.addAction = {

   setVariable: function(varName, value, options) {

      //blabla

      this.intent.addArg(/* blabla */);

   },

   flash: function(text, options) {

      //blabla

      this.intent.addArg(/* blabla */);

   }

};

Which make me able to do this :

var task = new TaskerTask();

task.addAction.setVariable(“VarName”, value);

The problem is : in the setVariable function, this isn’t defined anymore… and I need it….

I’m not sure it’s very clear.. ask if needed !

]]>

6 Commentsto I need someone good at javascript, because I’m facing a nice difficulty… :

  1. Anonymous says:

    < ![CDATA[

    JavaScript does not work as a class language, this is object oriented, hence this does not refer to the TaskerIntent object. There is no “instance” but only “objects”, with some kind of class simulation through the prototype mechanism. this does not implicitly link to the object, it only links to the owner of hte object. In this case this is the “addAction” object.

    ]]>

  2. Anonymous says:

    < ![CDATA[

    In this case, how can I pass the this reference from addAction to setVariable, flash, etc…?

    ]]>

  3. Anonymous says:

    < ![CDATA[

    I would suggest instead to not use the extra step “addAction”. I don’t think this is so useful.

    ]]>

  4. Anonymous says:

    < ![CDATA[

    That’s a bit true, but it was a naming “convention” problem : I wanted to have the word “add” separated from task and the action to add…



    How can I name it?


    I wanted : task.addAction.setVariable(name, value, option)


    And


    task.manageDefault.setVariable(newOptions)



    Any ideas?

    ]]>

  5. Anonymous says:

    < ![CDATA[

    I regret the “add”, but I’ll do something like :


    task.setVariable(“%Name”, value, {append: true});


    And


    task.overwriteDefaultOptionsFor(“setVariable”, {doMath: true});



    I could maybe do task.addAction(“setVariable”, “Name”, value, {doMath: true});


    But the addAction function will have variable number of args and would be giant ^^ and I don’t want it

    ]]>

  6. Anonymous says:

    < ![CDATA[

    Nevermind, I’ve found!


    Finally it’ll be :


    task.addAction(“setVariable”, [“%VarName”, value, {doMath: true}]);

    ]]>

Leave a Reply

Your email address will not be published. Required fields are marked *