javascriptoopwikitude

How JavaScript basic Object inherits parameters?


This is a snippet from Wikitude (an AR platform) written in JavaScript

this.tracker = new AR.ImageTracker(this.targetCollectionResource, {
    onTargetsLoaded: this.worldLoaded
});

My question is about the 'onTargetsLoaded' variable, where did it come from? I UNDERSTAND that the curleybraces is the same as

new Object();

But, still, why would a general object have such a specific parameter such as 'onTargetsLoaded'? this parameter exists only in classes the the AR plugin provides
and since the Object object doesn't inherit anything why would it have this parameter?


Solution

  • The object literal ( { ... } ) just contain keys and values, none of which have any semantic meaning whatsoever to the Object class. Any JS object can contain arbitrary keys and values, and it's down to the code that uses those keys to assign a semantic meaning to those keys.

    So, in this case, it's just being used as a way to supply values for keys that the AR.ImageTracker class itself already knows about.