Subj : Re: Checking JSObject class type To : Brian Genisio From : Brendan Eich Date : Mon Jan 26 2004 12:24 pm Brian Genisio wrote: > Yeah, that would work, but it assumes a specific implementation of the > jsapi... it assumes that the object's class spec has the same pointer > as the spec used to initialize the class. If the jsapi ever changes > it's implementation, and makes it's own copy of the JSClass structure, > this check will fail. That's pretty much guaranteed not to happen, but you're right that class name string equality is a looser, but still valid, way than JSClass address equality of deciding whether an object is an instance of a class. But the JS API you want, to hide all the details, is JS_InstanceOf. Note the way the optional argv parameter, if not null, makes this API report an error when returning false. One drawback to these JSClass*-parameterized approaches: the JSClass singleton for each class must be visible so that you can take its address. That's not the case for the native classes implemented by the engine itself, e.g. So the string equality test wins on that account, too, but it's slightly slower. /be .