1

How does one get the name of the Parse.Object instance (using Parse.com JavaScript SDK)? Say, I have a custom class called Contact, how do I check that an object is of class named Contact?

I tried the following console.logs following recommendations from this SO post, but none of the logs contain any reference to the Contact class:

console.log(Object.prototype.toString.call(contact));
console.log(contact.constructor);
console.log(contact.constructor.name);
0

1 Answer 1

1

I am assuming you want to know the corresponding Parse Classname for an object, this should be accessible through the className property of an object.

Here is a small Cloud Code function as an example that returns the object and the classname. However this is quiet pointless as you already know the classname of an object as you have to use it for your query.

Parse.Cloud.define("classname", function(req, res) {
    var TestObject = Parse.Object.extend("TestObject");
    var query = new Parse.Query(TestObject);
    query.first({
        success: function(obj) {
            res.success({
                object: obj,
                class: obj.className
            });
        },
        error: function(err) {
            res.error(err);
        }
    });
});
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Björn, this is what I was looking for. It may be, as you say, pointless in your example, but in my case it's very useful. Thanks again!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.