Is there any way to execute some function from console?
-
i have some function io my code
function func() { dosomething }
Is there some way to execute this function from console?
-
// Wrap function (function() { doSomething(); }) // Execute ();
It's was a nice way to workaround some input in the console because it didn't like
var blah = "Hellow"
until I wrapped it in a function.
-
I mean I have some functions in my modules in my code and i want tot call these functions from console
-
Use
require
If the code in the module is exposed like
module.exports = function() { myFunction; }
or
function myFunction() { } module.exports = { myFunction: myFunction }
You can use
require('myModule')()
orrequire('myModule').myFunction()
to execute the code
-
Thank you thsi helps a lot
-
You can also access variables defined in your main module.
-
To expand a bit on TheNumberOne's answer, if you defined your function like
func = function () {dosomethin}
it will be accessible globally (which includes the console). This removes the need to
require
anything on the console. Note the lack ofvar
, this is important. Bothvar func
andfunction func
limit the scope. If you want it to all hang out, don't dress it up
-
The scoping I posted about earlier no longer functions. sigh Time for a major rewrite of all my code.
-
I'm still using 1 global in my own code, not accessible anymore from console, but I'm hoping I can keep that global.
(apparently changing the globals triggers a deoptimalization in the v8 chrome/node endinge, I hope it's not a big one...)