Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>CurlJS and RequireJS both support the AMD <strong>AND</strong> CommonJS require call patterns:</p> <p>The difference between CJS and AMD is the use of Array as wrapper for the list of dependencies. Also note that in CurlJS's config you can alias <code>curl</code> to <code>require</code> to make your code fully compatible with AMD spec. Observe:</p> <p>CJS require call pattern:</p> <pre><code>var a = require('name') </code></pre> <p><strong>ONLY</strong> CurlJS AMD require call pattern:</p> <pre><code>var promise = require(['name']) promise.then(callbackFunction) </code></pre> <p>This commonly can be shortened to:</p> <pre><code>require(['name']).then(callbackFunction) </code></pre> <p>Note, CurlJS's returning of a Promise object is NOT part of the AMD spec. The AMD spec does not seem to prescribe a return value for AMD-style require call.</p> <p>Both, RequireJS and CurlJS support standard AMD require call patterns:</p> <pre><code>require(['name'], callbackFunction) </code></pre> <p>Again, note the use of Array as a flag that this is an AMD style require. That triggers different logic for return value.</p> <p>To make your thing work as you want, on CurlJS, your code must be inside a module that is wrapped as if it's a CommonJS module, use:</p> <pre><code>define(function(require) { ... }); </code></pre> <p>I am told that in that case, the <code>require</code> you get behaves like CommonJS style <code>require</code> - sync. In reality, what happens behind the scenes is the loader scans the factory function for things you require and folds them into list of requirements for that define. Then, inside the factory you can do:</p> <pre><code>var greeter = require('modXyz'); greeter.sayHi("Gracie"); </code></pre> <p>Note, the "sync" behavior is still an illusion, as what actually happens is that detected required resources are preloaded.</p> <p>On RequireJS even global <code>require</code> can be called CJS style: <code>var resource = require('resource/path')</code>, but only <strong>after</strong> you have already loaded it before. </p> <p>In other words, the loading always happens async in both CurlJS and RequireJS before the factory function runs, but in RequireJS you can use that almost everywhere, while in CurlJS it's very very niche scenario.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload