![]() Since you can attach a function directly to module.exports you can essentially return a function and like any function it could be managed as a constructor (That's in italics since the only difference between a function and a constructor in JavaScript is how you intend to use it. The cool part is that you don't see any of that in your CommonJS modules as the whole system takes care of that for you all you need to know is there is a module object with an exports property and an exports variable that points to the same thing the module.exports does. ![]() In the example above module.exports and exports are the same object. You may not feel comfortable for the first time, which is OK. ![]() In either case what is returned by require() is a reference to the value of module.exports.Ī pseudo-code example of how a module is defined: var theModule = )(theModule, theModule.exports, theRequireFunction) Note Constructor is a terminology from Object Oriented Programming. Or you can assign an object to the module.exports property. Once required in another module those assign properties become available. You can either use the exports variable provided to attach properties to it. That said your question about using the new keywords has a simple answer: Yes. Because functions are first class citizens in JavaScript they to can act just like Objects (technically they are Objects). If url is an absolute URL, a given base will be ignored. ![]() If url is a relative URL, base is required, and will be used as the base URL. In either case you are returning an Object/Function. A string or any other object with a stringifier including, for example, an or element that represents an absolute or relative URL.CommonJS modules allow two ways to define exported properties. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |