Hey there,
I'm getting tired of duplicating my JS code to define a macro and then define a normal JS function to do exactly the same thing.
Is there a way for me to invoke a macro that I previously defined in JS inside a JS function?
Simple place holder code:
Macro.add('MySugarCubeMacro',
{
handler: function()
{
console.log ("MySugarcubeMacro() invoked!");
}
});
window.macro_invoker = function()
{
// i have no clue how you do this...
Macro.Invoke("MySugarCubeMacro");
}
Thank you for your answer!
Comments
There are other ways too, but that's the one I've seen most often recommended, and the one I usually use.
E.g.
Because macro definition is basically just a thin abstraction layer around Javascript code evocation and using <jQuery>.wiki (or a Wikifier) in this case to evoke the same code from two locations is an expensive operation.
On the other hand it is very unlikely that anyone but yourself is going to add new properties to the setup object, which SugarCube supplies for the Author's use.