简体   繁体   中英

Javascript OOP variables from class

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.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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM