When using `require('backbone')`, the returned object can vary depending on the file it is called in

backbone1.js

var backbone1=require('backbone');
window.backbone=backbone1;

backbone2.js

console.log(window.backbone===require('backbone'));

Why is the condition returning false. Shouldn't it return the same object everytime?

Edit:

index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8>
     <title>Document</title>
</head>
<body>
    <script src="bundle1.js"></script><!--backbone1.js gets compiled into bundle1.js-->
    <script src="bundle2.js"></script><!--backbone2.js gets compiled into bundle2.js-->
</body>
</html>

Answer №1

When it comes to comparing two objects for equality, using === is not the way to go. Thank goodness for Backbone's dependency on underscore, because you can utilize _.isEqual for this task.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

When I run `npm update -g`, my npm mysteriously disappeared

I am using Mac OSX and need to update all globally installed items with npm. However, when I ran npm update -g, I encountered a lot of errors and npm disappeared. Here's what happened: localhost:~ myname$ npm -bash: npm: command not found I tried s ...

Encountering a "require is not defined" error when trying to launch a Selenium

I have developed a basic selenium application and now I am looking to implement a graphical user interface for it. Here is the code snippet: index.html: <html> <head> <meta charset="UTF-8" /> <title>Selenium Ap ...

When I click a button in d3 to refresh the data on my bar graph, the text fails to update accordingly

I've successfully created a series of data lists that modify the bargraph. Unfortunately, due to their differing x and y values, they end up printing new values on top of existing ones. Shown below is an image illustrating the issue where x and y val ...

How can I implement user account functionality with only JavaScript in an Angular frontend and Node.js/Express server?

Many resources I've come across utilize php or a similar language. With an Angular frontend and Node/express server code in place, but no backend yet, I'm uncertain about how to approach user sign-up. ...

The $scope variable fails to reflect updates in the view following a broadcast event triggered by a

I have been troubleshooting a similar issue and I can't seem to figure out why the update is not reflecting in the view. While I am able to see the scope variable updating in the catch events logs, the changes are not being displayed in the view. For ...

Issue with parameter functionality not working as expected

This code snippet is not functioning as expected. I am trying to extract and print the values from the URL parameter file:///C:/Users/laddi/Desktop/new%201.html?t=vindu&b=thind function GetURLParameterValue(param) { var pageURL = window. ...

The onClick event's detail property is persisting even after the React component has been replaced

In the onClick event, the value of event.detail indicates the number of clicks, with a double-click having event.detail = 2. It seems that when the React component being clicked is replaced, the event.detail value does not reset. This could be due to Reac ...

Having trouble locating the module for my custom TypeScript module

Exciting news! I have recently released a new TypeScript-based module on the NPM registry, called ooafs. However, when attempting to install and import it into another TypeScript project, an error pops up in VSCode stating: Cannot find module 'ooafs&a ...

What could be the reason for a particular product edit page showing up completely blank?

In my ongoing project, I am developing an admin panel that allows administrators to add new products to their website. These products are then stored in a Firestore database and managed using Redux Toolkit. The added products can be viewed and edited in th ...

Accessing the Azure billing API allows users to view and

I am interested in developing a dashboard that includes detailed graphs outlining the costs of my Azure resources. Simply viewing monthly invoices is not sufficient for me, although I would be satisfied with that at this point. Upon researching further in ...

Using JavaScript to Apply CSS Styles in JSF?

Is it possible to dynamically apply a CSS style to a JSF component or div using Javascript? I have been searching without any success. Below is some pseudo code: <div style="myJSStyleFunction("#{myBean.value}")"> stuff </div> The function wo ...

Attempting to showcase a collection of values, specifically focusing on highlighting the even numbers within the array

const sampleArray = [ 469, " " + 755, " " + 244, " " + 245, " " + 758, " " + 450, " " + 302, " " + 20, " " + 712, " " + 71, " " + 456, ...

Error encountered on macOS Mojave M1 when trying to set global permissions for npm bin folder

After running the npm doctor command, here is the output I received: npm ERR! checkFilesPermission Missing permissions on /opt/homebrew/bin/.keepme (expect: executable) Check Value Recommendation/Notes npm ping ...

What is the proper way to handle a 504 response header in an AJAX request using jQuery?

Recently, I encountered an issue with an AJAX call from the client that caught my attention. Here is a snapshot of how it looked: $.ajax({ 'url': '/converter/ajax-make-corrections/', 'data': { ...

Creating movement in three distinct divisions

I am seeking a way to have three divs flying in upon click. The first DIV is positioned at the top, followed by one on the left and one on the right (both being below the top one). I wish for them to fly in from their respective directions - the top div fr ...

What could be causing the queuing of multiple Ajax requests in ExtJS?

I am encountering an issue with my grid setup. I have a menu on the left side for each item on the grid, and this menu's items change based on the selection in the grid. When the event selection is triggered, an Ajax.request function is called to hand ...

How can one properly extend the Object class in JavaScript?

I have a scenario where I want to enhance a record (plain Javascript object) of arrays with additional properties/methods, ideally by instantiating a new class: class Dataframe extends Object { _nrow: number; _ncol: number; _identity: number[]; co ...

Error: npm start encountered a Microsoft JScript runtime error with code 800A138F, indicating that

Starting with NPM for beginners... To kickstart my app, I use the command below. node app However, upon running this command, an error pops up when I try: npm start Error message displayed: Windows Script Host Object expected Line 2 800A138F M ...

discovering a new type of mutation through the use of Vuex

Vue Component computed: { score () { this.$store.commit('fetchCoordinates'); console.log(this.$store.getters.cordinate); } } store.js export default { state: { lat:'ok', }, getters:{ cordinate(state){ r ...

What is causing my ajax request to malfunction?

I'm encountering an issue while trying to send a request using AJAX. The request is successful when I use the following webservice: https://jsonplaceholder.typicode.com/users However, when I attempt to make the same request with my own service, I fac ...