Set Up Jsfiddle With Requirejs, Socketio, Backbone
Solution 1:
Lots of errors.
You should not use the HTML window at all for this. You can put everything in the JS window.
You should not put
.js
extensions in paths.There's no need to use fallbacks for the code you have the the values in
paths
should be strings rather than arrays.You had typos in your URLs in
paths
.This line
var io = require('socket.io')
cannot work. This is RequireJS, not CommonJS. Such a call could work inside adefine
call.Backbone has not needed a
shim
for quite a while now. Yourshim
for it is useless.You don't need to do
Backbone.$ = $
.For historical reasons both jQuery and Backbone leak themselves into the global space. So you don't have to do this manually.
Here's the cleaned up JS:
requirejs.config({
paths: {
'socket.io': 'https://cdnjs.cloudflare.com/ajax/libs/socket.io/1.5.1/socket.io',
'jquery': 'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0/jquery.min',
'underscore': 'https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min',
'backbone': 'https://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.3.3/backbone-min'
},
waitSeconds: 3
});
require(['jquery', 'underscore', 'backbone', 'socket.io'], function(jq, us, bb, io) {
console.log($, Backbone.$, Backbone);
});
Note how the console.log
relies on $
and Backbone
being in the global space.
And a fork of your fiddle.
Post a Comment for "Set Up Jsfiddle With Requirejs, Socketio, Backbone"