requirejs

In RequireJS - Cannot alias jQuery name in path

你说的曾经没有我的故事 提交于 2019-12-10 13:16:11
问题 I'm a RequireJS noob. When I use "require.config" and include a path to jQuery with a name different than jQuery, results are not as expected. Here's a very simple example to help explain my issue. Structure of files root ├── Index.htm └── scripts ├── libs │ ├── jquery-1.7.1.js │ └── require.js ├── main.js └── someModule.js index.htm <html> <head> <title>BackboneJS Modular app with RequireJS</title> <script data-main="scripts/main" src="scripts/libs/require.js"></script> </head> <body> <h3

Load requireJS module inline the HTML body?

二次信任 提交于 2019-12-10 12:32:58
问题 I am integrating RequireJS in a CMS so I placed this on the bottom of my page template: <html> <body> {Placeholder1} <script src="scripts/require.js" data-main="scripts/main"></script> {Placeholder2} </body> </html> Then on each page, I would like to create a function that leverages RequireJS. So I tried placing this on the bottom of the page: <html> <body> <h1>Home</h1> <div class="slider">Slider content</div> <script src="scripts/require.js" data-main="scripts/main"></script> <script type=

What is “define” in RequireJS?

给你一囗甜甜゛ 提交于 2019-12-10 12:25:53
问题 What is define in RequireJS? Is it a constructor or a function or...? Create module app. Before create module it loads module app2. After initialize callback: define( 'app', ['app2'], function( app2 ){ console.log(app2) } ); What's this syntax? define(function (require) { var logger = require("./app2"); console.log(logger); }); And this: define({ color: "black", size : "large" }); 回答1: From the comments: The function that handles definitions of modules. Differs from require() in that a string

Requirejs, what it means “Requirejs loads each module once”

大兔子大兔子 提交于 2019-12-10 11:46:15
问题 So if i have some module like: //test1.js define([], function() { var counter = 0; return { increment: function() { counter++ } }; }); Requirejs will load this module once(to be aware of local variables of this module) and never again? Variable counter will be alive through closure from returning object(through increment function)? What about next example? //test2.js define([], function() { var value = 10; document.getElementById('asd').addEventListener('mousedown', function(e) { value = Math

Front end javascript testing using Require and Resharper

隐身守侯 提交于 2019-12-10 11:39:38
问题 So I've been trying to figure out how front end testing works (unit testing) but I am getting stuck on some point. So I have my jasmine test set up as follows: describe('Blabla', function () { it('returns true', function () { var people = require(["people"], function(ppl) { return ppl; }); expect(people.getTitle()).toBe('People piolmjage'); }); }); But running this gets me: TypeError: undefined is not a funtion So obviously, people is undefined. So perhaps my callback comes in too late. But

How to call a function within the same module?

一个人想着一个人 提交于 2019-12-10 11:34:21
问题 I'm trying to get my head round RequireJS in order to tidy up my app. I have a few modules, and a main.js script. In my main.js, I am defining a module that contains a few AJAX functions, to make basic API calls. Inside this "API" module, I am first calling one of the AJAX functions, which after completion, needs to call a different AJAX function, inside the same "API" module (as these are Async tasks, I thought chaining them like this would be OK?!). But, just calling the function name

Require.JS and JS Test Driver: Unexpected token <

你离开我真会死。 提交于 2019-12-10 10:35:37
问题 I am trying to test a simple Backbone Model loaded via RequireJS: define ["backbone"], (Backbone)-> class Todo extends Backbone.Model defaults: title: '' priority: 0 done: false validate: (attrs) -> errs = {} hasErrors = false if (attrs.title is "") hasErrors = true errs.title = "Please specify a todo" if hasErrors return errs toggleDone: -> @save("done", !@get("done")) return Todo My tests look like: requirejs.config baseUrl: "js/" paths: jquery: "https://ajax.googleapis.com/ajax/libs/jquery

How can I import TypeScript AMD modules without making the dependent code a module

女生的网名这么多〃 提交于 2019-12-10 10:19:22
问题 I have a Chrome extension content script that has 2 AMD dependencies. The script works fine when I load the dependencies using the requirejs "require" function. I ported the script to TypeScript with the rest of my project, and am now using import Dependency = require("Dependency"); which is all fine and dandy, the modules have been ported to TS and are working fine in other parts of the project. My issue is that as soon as I add an import statement, the TS compiler wants to make my script

DataJS library not loading in RequireJS

[亡魂溺海] 提交于 2019-12-10 10:04:36
问题 I am new to RequireJS, so this might be a stupid question! I am using require-jquery. I want to load the DataJS library as a module. It is a standalone library and does not depend on jQuery. This is what my HTML file start.htm looks like: <html> <head> </head> <body> <script type="text/javascript" src="Scripts/Loader.js"></script> </body> </html> This is what the Loader.js file looks like: (function (window, undefined) { var script = document.createElement('script'); script.async = true;

requirejs: Module name “underscore” has not been loaded yet for context [duplicate]

岁酱吖の 提交于 2019-12-10 08:17:56
问题 This question already has answers here : Trouble combining Require.js and Backbone.js/Underscore.js (3 answers) Closed 2 years ago . I always get this error when I freshly load my app, Error: Module name "underscore" has not been loaded yet for context: _. Use require([]) http://requirejs.org/docs/errors.html#notloaded ...,h){c=Error(c+"\nhttp://requirejs.org/docs/errors.html#"+b);c.requireType=b;c.re... require.js (line 8) TypeError: Backbone.Model is undefined var ProjectModel = Backbone