class Child extends Parse.Object {
constructor() {
super("Child");
}
}
new Parse.Query(Child).find().then((children) = {
if (children.length > 0) {
console.log(children[0] instanceof Child); // prints "false"
}
});
Works when Child is specified with old Parse.Object.extend syntax
what your showing is problematic. because Parse.Query cannot magically access this class that you created by this syntax. also if you'll have two declaration of the same class Child extends Parse.Object {路路路} JavaScript won't treat instance of one of them of the other. it's part of the way JavaScript works.
As everything else in JavaScript, it would advice to use duck typing checking:
children && children[0] && children[0].className === 'Child'
When using es6 classes to extend Parse.Object you must register the subclass: Parse.Object.registerSubclass("className", constructor)
Just have a registration follow the class declaration:
class Child extends Parse.Object {
constructor(attributes, options) {
super("Child", attributes, options);
}
}
Parse.Object.registerSubclass('Child', Child);
Hi @myuller, we maintain an inner classMap to keep track of all subclasses of ParseObjct. When objects of a subclass are retrieved from a query, if we can find the subclass in the classMap, the objects will be instantiated with this subclass. In order to use the subclass in es6, you have to manually call registerSubclass. For es5, we have done that for you in extend, check here.
Thanks for your awesome explanation @TylerBrock.
@TylerBrock @wangmengyan95 Thank you!
Most helpful comment
When using es6 classes to extend Parse.Object you must register the subclass:
Parse.Object.registerSubclass("className", constructor)Just have a registration follow the class declaration: