a.js
define(function(require, exports, module) { var test = function(){ console.log("hello world") } //if using just this, Tern doesn't get it, but works with RequireJS module.exports = test; //this works with Tern already // return test; });
test.html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> </head> <body> <button οnclick="test()">test</button> <script> function test() { require(['./a.js'], function (sayHi) { console.log(sayHi); }); } </script> <script src="https://requirejs.org/docs/release/2.3.6/minified/require.js"></script> </body> </html>