Questions tagged [requirejs-define]
35 questions
180
votes
2 answers
What is define([ , function ]) in JavaScript?
I see this being used all the time in JavaScript:
define(['param1', 'param2'], function() {
});
What is the define function?

vinzzz
- 2,084
- 2
- 14
- 23
169
votes
2 answers
What is 'define' used for in JavaScript (aside from the obvious)?
I have searched high and low for documentation on this, but I just cannot find anything anywhere.
I am using Aloha and want to use their sidebar prototype to create a new side bar of my own attached to other plugin functionality.
Their sidebar.js…

David O'Sullivan
- 2,969
- 4
- 21
- 24
7
votes
1 answer
What is exactly define(function(require){...}) in JavaScript
I understand that define is used to define a module, and function is an anonymous function, but what does the argument 'require' in the function hold?
If I write anything in define(function(require){...}), when will this be called? How to give a…

Tehreem
- 476
- 9
- 23
4
votes
2 answers
RequireJS - When specify module id in define()
In RequireJS documents (http://requirejs.org/docs/api.html#modulename), I couldn't understand this sentence.
You can explicitly name modules yourself, but it makes the modules less portable
My question is
Why explicitly naming module makes less…

chris
- 714
- 2
- 7
- 18
4
votes
3 answers
How to load JSONP inside requireJS?
I'm trying to get a JSONP file to load in requireJS. The docs say it should work like this:
require(["http://example.com/api/data.json?callback=define"],
function (data) {
//The data object will be the API response for the
…

frequent
- 27,643
- 59
- 181
- 333
3
votes
1 answer
RequireJs define parameters
In the official guide of RequireJs there's a define example:
define(["require", "./relative/name"], function(require) {
var mod = require("./relative/name");
});
The first dependency, "require" is returned and inserted into the first parameter…

Gart
- 1,485
- 2
- 11
- 15
3
votes
5 answers
How do I get global scope inside define function?
Can you get global scope while using strict mode and also making sure that you can run on non window environment.
See these examples:
define(['other', 'thing'], function() {
// this === window in desktop environment
// this === GLOBAL in…

Andreas Louv
- 46,145
- 13
- 104
- 123
3
votes
1 answer
RequireJS: defining in callback
In my module I want to defer the "define" call, but RequireJS running callback once file is loaded, not when "defined"... For example:
a.js:
require(['b'], function(b){
console.log(b);
});
b.js:
define({'foo':'bar'});
This works as expected…

Buncha
- 51
- 5
2
votes
1 answer
Load sigmajs through requirejs
I am trying the RequireJS AMD,
And would like to load - among others (jquery, bootstrap, d3, moment...) - the graph library sigmajs,
But when I load it in a module,
It is undefined... However it exists in the window object...
Is it a bad practice to…

Flo Schild
- 5,104
- 4
- 40
- 55
1
vote
0 answers
requirejs - Getting an error loading last module in define array([])
I have been experiencing an error to load the last module in define array.
Ex:
define(['jquery', 'js/custom','moment','bootstrap','datetimepicker'], function ($, custom) {
$('#input_start_date').datetimepicker({});
));
Getting an…

Bijal
- 11
- 1
1
vote
1 answer
How can i have multiple module instance with requirejs
I try to work with RequireJS and AMD module definition and have write a module that do my things in object format i think.
(i went from jquery and have not study a OOP javascript well)
myModule.js
define([
jquery,
datepicker,
], function ($,…

Artur Mamedov
- 597
- 1
- 7
- 17
1
vote
1 answer
RequireJS configuration with modules that have no AMD support
So I'm trying to read the Require JS API -documentation to figure out how this should be done properly, but I've been unable to load a library so it doesn't get defined as undefined. I'm using this through NPM-WebJars, though I guess it shouldn't…

mpartan
- 1,296
- 1
- 14
- 30
1
vote
0 answers
Visual Studio 2015 intellisense for RequireJS modules
I am working on a React project, using RequireJS to manage my client side libraries. However Intellisense does not seem to grasp React inside my modules when I do a
define(
['react'],
function (React) {
...
}
)
How can I fix…

beruic
- 5,517
- 3
- 35
- 59
1
vote
2 answers
RequireJS: Different count of dependencies and params at callback function
I have legacy code and a module definition like this:
define(["a", "b", "c", "d"], function(a, b, c) {
...
});
You can see that there are more dependencies than actual params that we are using at module.
Does it make any sense? I think module…

Viacheslav Kondratiuk
- 8,493
- 9
- 49
- 81
1
vote
0 answers
Mismatched anonymous define() in requirejs/angular
Yes, I know this has been asked ad infinitum here, and I already know the general rule that when using requirejs, everything that calls define() must be loaded through a single script tag as in: