how can i use require(""); in javascript

333 views Asked by At

i want to use a plugin in Firefox that it is in this. in this plugin tutorial use require function, and it is: require("sdk/preferences/service");

but i get error that require is not defined. so i search and download requireJS. but when attach this i get error module name sdk/preference/service has not been loaded yet from context. use require([]).

so i use require(["sdk/preferences/service"],function(pref){}); but in function i can't use pref and get error script error sdk/preferences/service

so how can i use require function?

or a HTML example that use require function and it works correctly?

1

There are 1 answers

0
icktoofay On BEST ANSWER

The code you found was for use in a Firefox extension. You’re not writing a Firefox extension, you’re using a web page, so you can’t use that code. There’s no drop-in replacement; you’ll have to find something else.