可能重复:
javascript对象,访问变量属性名称?
试图在我的JS中获得更高级...
我有一个自定义对象:
Object myObject = new Object();
myObject.thing = anythingHere;
Run Code Online (Sandbox Code Playgroud)
我希望能够通过传入一个字符串来检索自定义对象属性...例如:
var propertyString = 'thing';
alert(myObject.propertyString);
Run Code Online (Sandbox Code Playgroud)
我无法理解这一点.我已经查看了一些自定义对象的教程 - 但没有显示如何获取我不知道名称的属性...另外 - 如果可能的话,我想避免遍历所有属性...
谢谢!!!
OBeen 用这个把我的头撞在桌子上,我尝试了在 SE 上找到的答案。请帮忙。
我有一个函数可以轮询 api 来获取新数据。我想要的只是该函数每 10000 毫秒重复一次。我认为以下方法会起作用:
//SURVIVORS_OBJECT
//Store the suvivor object and append the map markers and some additional parameters to it
var survivorMarkers;
function dz_survivorMarkers(){
//The survivors will be stored as an 'armaMapMarker' object
this.survivors = {};
//Clear a survivor from the list because by id (eg: has not been returned in our query)
this.clearSurvivor = function(pId){
this.survivors[pId].marker.setMap(null);
delete this.survivors[pId];
};
//make the api request from the overwatch data api
this.getSurvivorsRequest = function(){
console.log('UDBG:::survivorMarkers.getSurvivors ENTERED');
//the …Run Code Online (Sandbox Code Playgroud)