2015-04-01 97 views
0

添加一个方法我有这样的对象:问题与对象

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

这工作:Point.step();

如何使它符合[ ]表示法?含义Point["property_name"]

+6

'点[ “步骤”]()'? – 2015-04-01 08:25:52

+0

@ArunPJohny你能否写下你的评论作为答案,以便你可以拿出信用回答这个问题? :) – eAbi 2015-04-01 08:31:16

回答

1

它是Point["step"]();。这里是片段:

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

 
Point["step"]();

+1

这太容易了;此外,已经[由Arun P Johny指出](http://stackoverflow.com/questions/29386067/issue-with-adding-a-method-in-object#comment46950309_29386067)。 – nicael 2015-04-01 08:31:01

+0

Point [“step”]()起作用。非常感谢! – Anamed 2015-04-02 08:12:14