Trouble including JavaScript file (Vaadin 14.1.3)

I am trying to call a custom javascript function but I cannot seem to get the js file to be included.

I have the javascript file in:

	/frontend/js/myfunc.js

containing:

	var NS =
	{
	    testJS: function (id)
	    {
	        console.log('NS::testJS - ' + id);
	    }
	}

and have added the annotation to my main class:

	@JavaScript("./js/myfunc.js")

However, the following shows an error in the console (Uncaught ReferenceError: NS is not defined):

	Page page = UI.getCurrent().getPage();
	page.executeJs("NS.testJS($0);", "Bob");

The following code works as expected:

	Page page = UI.getCurrent().getPage();
	page.executeJs("console.log($0);", "Bob");

The above javascript is just a simple test case to demonstrate the issue.

Running Vaadin 14.1.3 and Spring Boot 2.2.2.

Define NS on the window, as the loaded javascript is scoped to the component and not the whole page/window. If you then execute js on the page level, NS is not defined in that scope.

window.NS = {
	testJS: function (id)
	{
		console.log('NS::testJS - ' + id);
	}
}

UI.getCurrent().getPage().executeJs("NS.testJS($0);", "Bob"); should now work fine. If not, try importing the js with @JsModule (I’m not too sure what the difference is but its worth a try)

Thanks Kaspar.
Adding the ‘window.’ works perfectly.