Time for class?
var scorm = new SCORM();, much like my SCORM ActionScript classes.
Last weekend I went ahead and converted the wrapper to a class just to see how I’d like it. Verdict: It’s kind of neat I guess, but it isn’t really an improvement over the SCORM “object” method I used in the first wrapper.
One of the benefits of using a class is that you can create multiple objects that inherit from the class, such as:
var bmw = new Car(); var toyota = new Car(); var volkswagen = new Car();
But with SCORM, you really don’t want more than one SCORM object… it would totally kill the LMS communication. Scratch that perk.
Another perk of using classes is that you can ‘wrap’ all of your variables and functions into the class and keep the global namespace clean. Well, the object approach used in the first wrapper has the exact same number of global variables used in the class approach: one. Scratch that perk, too.
var sco = new SCORM();
var s = new SCORM();
This means the ActionScript classes would need to be updated anytime the developer uses a different object name. Advantage: object approach.
So I guess I’ll stick to the object version. 🙂
Speaking of the object version…
I updated the wrapper to version 1.1.5. I haven’t uploaded it yet, because I still need to test it out. It passes JSLint, but I need to run it through my various SCORM tests to make sure it works OK.
Here is a quick list of changes & improvements.
Changed the global variable from
No, this isn’t vanity run amok, it’s a simple programming convention to prevent naming conflicts; the variable
pipwerks is less likely to run into naming conflicts in an online course than a variable named
SCORM. But, rest assured, if you prefer to use the variable
SCORM, all you need to do is add this line at the top of your HTML file after you import the wrapper file:
var SCORM = pipwerks.SCORM;
Added some shortcuts to make coding a little easier. Instead of
var success = pipwerks.SCORM.connection.initialize();
you can do
var success = pipwerks.SCORM.init();
Here are all of the shortcuts I added:
pipwerks.SCORM.init = pipwerks.SCORM.connection.initialize; pipwerks.SCORM.get = pipwerks.SCORM.data.get; pipwerks.SCORM.set = pipwerks.SCORM.data.set; pipwerks.SCORM.save = pipwerks.SCORM.data.save; pipwerks.SCORM.quit = pipwerks.SCORM.connection.terminate;
If you use the scorm renaming example I just showed you, your code could be as concise as this:
var sco = pipwerks.SCORM; sco.init(); sco.get("cmi.core.lesson_location"); sco.set("cmi.core.lesson_location", "http:pipwerks.com"); sco.save(); sco.quit();
Nice and short, huh?
Relocated some functions
Now that the global namespace is
pipwerks, I was able to move some non-SCORM stuff out of the
SCORM object. Specifically, I moved
pipwerks.UTILS.StringToBoolean. Small tweak, but it helps keep things tidy.
To make the code more concise (and shorter), I replaced the if SCORM 1.2 / else if SCORM 2004 statements with
switch statements. They’re just as effective and take much less space.
I also cleaned up the commenting a bit in an effort to make it more readable.
I decided to change the copyright notice I had been using (Creative Commons) to the more widely supported MIT-style license. I’ll still be using Creative Commons licensing on my examples and other files, but for pure code-stuff, the MIT-style license will probably work best for most people.