简体   繁体   中英

issue with adding a method in object

I have this object:

var Point = {
    step: function () {
        alert("hello");
    }
};

This works: Point.step(); .

How to make it work with the [ ] notation? Meaning Point["property_name"] .

It is Point["step"](); . Here is the snippet:

 var Point = { step: function () { alert("hello"); } }; Point["step"](); 

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