• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: How is the constant being set?

Resolved: How is the constant being set?

0
By Isaac Tonny on 18/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

I am trying to understand the following code, but cannot get what exactly the line const ej2_popups_1 = require("@syncfusion/ej2-popups"); is doing? I searched online and found that the require statement is loading a module, but then the question comes up what exactly is the use of const ej2_popups_1 and which object i.e. full name like aaa.bbb.ccd.Dialog it represents.
The reason I need the fully qualified name is because I want to override a method called someMethod in ej2_popups_1.Dialog.prototype.someMethod.

Answer:

In the RequireJS pattern, you don’t have to define things as globals, but rather you have two globals: require and define, which let you create and use modules.
from RequireJS docs: https://requirejs.org/docs/api.html#define

A module is different from a traditional script file in that it defines a well-scoped object that avoids polluting the global namespace. It can explicitly list its dependencies and get a handle on those dependencies without needing to refer to global objects, but instead receive the dependencies as arguments to the function that defines the module.


so, this require function does the work of “window” – in that it knows about your other dependencies. and its not as tightly coupled – a variable vs something configurable like a lookup based on a string name of a package/module. the mechanics of how it works are described here as well

If you have better answer, please add a comment about this, thank you!

javascript
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: how to get and read an xml file in a zip file using xml.etree

02/04/2023

Resolved: The ‘Access-Control-Allow-Origin’ header contains multiple values ‘*, *’, but only one is allowed. cors error not resolving

02/04/2023

Resolved: SQLSTATE[42S02]: Base table or view not found: 1146 Table ‘crm.email’ doesn’t exist (Connection: mysql, SQL: select count(*) as aggregate from `email`

02/04/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.