javascript object property splicing

In the object method, you need to pass a variable to call the display object belonging to the name, you can do this

var person = {
            borther1: { name: "tom" },
            borther2: { name: "jack" },
            borther3: { name: "david" },
            sayBorther: function (num) {
                return this["borther"+num]
            }
        }

We know that person.borther1 is equivalent to person["borther"],

Person["borther"] is written with string concatenation as person["borther"+1]

applied to the above method

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324887697&siteId=291194637