I know almost enough JavaScript to be dangerous. While working on a locking problem I discovered the action "com.vmware.pscoe.library.locking/Locking" and would like to use it as this could save me some coding time. My problem is that I don't understand JavaScript well enough. The meat of the action looks like this:
var logger = System.getModule("com.vmware.pscoe.library.logging").getLogger("com.vmware.pscoe.library.locking.Locking");
var Owner = System.getModule("com.vmware.pscoe.library.locking").Owner();
return function(lockId) {
if (lockId.indexOf(",") > -1) {
logger.error("Lockid contains illegal character: ','");
throw "illegal character in lockId: ','";
}
var owner = new Owner();
this.getLockId = function() {
return lockId;
}; this.getOwner = function() {
return owner;
};
this.lock = function() {
blah blah blah
};
this.unlock = function() {
more blah blah blah
};
and so on with a number of other "this.<name> = function() {}" code blocks
}
My quesitons:
I don't have this locking action/package, but from the bits you have shown it probably can be used in the following way:
// first, obtain an instance of the locking object
var Locking = System.getModule("com.vmware.pscoe.library.locking").Locking();
var locker = new Locking("my_lock_id");
// and then call its methods
locker.lock();
... // do something during the lock is acquired
locker.unlock();
This helped. I did some more digging based on your reply and found similar code.
My real problem as it turns out is not realizing or understanding that functions in JavaScript are treated as objects. Coming from a DOS/VBScript/PowerShell/bash scripting background this is an interesting concept.
Now the idea of this action returning a function makes sense.
P.S. Somehow, my OP didn't get posted as a question which means I can't mark this as answered. Unless someone knows how to convert a thread to a question...