我已经在java脚本中创建了一个 map ,我试图进入else block ,但出现以下错误。 我无法正确理解和调试它。
Uncaught TypeError: undefined is not a function
fruits : apple,orange,pineapple
countries:usa,uk,india,australia
cities:frankfurt,berlin,moscow
var map ={};
map['fruits'] = myObj1;
map['countries'] = myObj2;
map['cities'] = myObj2;
function get(k) {
return map[k];
}
if{
//dosomething
}
else{
var test2=map.get('fruits');
}
最佳答案
尝试
var test2 = get('fruits');
因为map没有方法get,
或更改 map 对象
var map = { get: function (key) { return this[key] }};
关于javascript - 未捕获的类型错误 : undefined is not a function when readind map in javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27548302/