Why do I have a backbone. $ = Require ('jquery') in the browser

I read this article and practice it myself.

If I remove the backbone. $ = $, the code will not work. What for?

var Backbone = require('backbone');
var $ = require('jquery');
Backbone.$ = $;

module.exports = Backbone.View.extend({
  initialize: function(){
    console.log('wuuut')
    this.render();
  },

  render: function(){
    $('body').prepend('<p>wooooooooooooooo</p>');
  }
});

Why in node js do I need to assign jquery to a member of a Backbone object?

+4
source share
1 answer

Backbone has this code by default:

// For Backbone purposes, jQuery, Zepto, Ender, or My Library (kidding) owns
// the `$` variable.
Backbone.$ = $;

If you download your modules with require, it is $not available for the trunk, so you must install it manually. And if you do not Backbone.View, that depends on jQuerywill not work.

+3
source

Source: https://habr.com/ru/post/1543019/


All Articles