How can I access a package scope to run a function defined inside a package


I’ve made a function in my package called getEditorFromPath() which, given a file path, returns the atom editor instance which has it open.

How can I access this function from outside of the package? For example, how would I run it in the dev tools console?


Every package can access the global atom object and set things on it. You can assign a function to it with this syntax:

atom.myPackage.getEditorFromPath() = this.getEditorFromPath()

Then, from the dev tools, you can use atom.myPackage.getEditorFromPath() to run that function.


Cool. I guess that’s a workaround. Strange there’s no way to access them directly. Thanks a lot anyway!


You can also use the atom.packages.getActivePackage() method, as well. If you do, your function will be under pkg.mainModule.getEditorFromPath().