1

Ey everyone, I am trying to make a javascript class and get its data off the class. Here's a snippet of the code:

    var App = {

    data: {
        string = "String"
    }

    login: function() {
        return alert(data.string);  
    }
}

var me = App.login();

Well, what I am trying to accomplish is getting the string value off data and alert it. What am I doing wrong?

1 Answer 1

2

1.In Object literal you must use : instead of =.

2.to get property in object use this (this.data.string)

3.add , after data: {}

var App = {

    data: {
        string: "String"
    },

    login: function() {
        return alert(this.data.string);  
    }
};

var me = App.login();

Example

Sign up to request clarification or add additional context in comments.

Comments

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.