how does yepnope js test object work?

136 Views Asked by At

I know this package is deprecated but would like to understand what's going on -

Looking at the docs, does the below mean that if window.JSON is true, run the complete function? And if not, load up the nope file?

yepnope({
  test: window.JSON,
  nope: 'json2.js',
  complete: function () {
    var data = window.JSON.parse('{ "json" : "string" }');
  }
});
1

There are 1 best solutions below

0
Madness On BEST ANSWER

No, complete is a callback that is always called regardless of what happens when all (or even when nothing loads) the resources are loaded.

You will need a yep:

yepnope({
   test: window.JSON,
   yep: 'json1.js',
   nope: 'json2.js',
   complete: function () {
      alert('done');
   }
});

The example from their page you had copied is for loading a script ONLY when a test fails, and nothing when it passes.