I am running JavaScript inside a Java application and have a gui terminal where I can print things by calling:
js.say("foo")
(js is an imported Java object, so yea I am running on the JVM). Now, I would like to redefine a:
print("foo")
call into a call to js.say("foo"). I can do:
> b = function(s) {js.say(s)}
sun.org.mozilla.javascript.internal.InterpretedFunction@39ffbc2e
> b("wee")
wee
But when I do:
> print = function(s) {js.say(s)}
sun.org.mozilla.javascript.internal.InterpretedFunction@6a7c8bd
> print("wee")
It seems I am not calling the new print function but the same old one if you get my drift. Is there a way to do what I am trying to do or am I doing something fundamentally wrong here?
Some functionname and variables are part of the languages namespace so you can’t redefine them.
What you can do and you already did it in your first example is to define a new function ‘textout’ and define an action.