Cannot read property 'xxx' of undefined

Cannot read property xxx of undefined

这个错误很好理解,就是使用.xxx的那个对象为undefined,
类似的报错还有Cannot read property 'xxx' of null
看个例子
  1. try{
  2. var b= undefined;
  3. var c = b.length;
  4. } catch(err){
  5. console.log(err.stack);
  6. }
b定义为undefined,再使用b.length就会报这个错误,

如果b定义为null,

报错信息的第二行直接就定位到了什么文件多少行.微笑
只是对于初学者有点懵逼.出现这种错误应该算是比较好解决的

猜你喜欢

转载自blog.csdn.net/csflvcxx/article/details/81030764