代码异常/资深js难点

2019-05-09  本文已影响0人  郁南

HTMLCollection

资料参考:链接<br />HTMLCollection是一个特殊的NodeList,表示包含了若干元素(元素顺序为文档流中的顺序)的通用集合,它是实时更新的,当其所包含的元素发生改变时,它会自动更新。另外,它是一个伪数组,如果想像数组一样操作它们需要像Array.prototype.slice.call(nodeList, 2)这样调用。

// exp:
    // const cList = document.getElementsByClassName('item'); // 报错
    // const cList = Array(document.getElementsByClassName('item')); // 报错
    // for (let q = 0; q < cList.length; q++) { // 报错
    //   const className = cList[q].getAttribute('class').split('-')[1];
    //   arr.push(className);
    // }

    const cList = Array.prototype.slice.call(document.getElementsByClassName('item'), 2); // 正确
    const arr = [];
    for (const el of cList) { // 正确
      const className = el.getAttribute('class').split('-')[1];
      arr.push(className);
    }

Angular:Internal error: unknown identifier at Object.importExpr$$1 [as importExpr]

angular在打包运行 ng build --aot --prod 报错 Internal error: unknown identifier at Object.importExpr$$1 [as importExpr] 的时候,原因是编写 service 或者 component 等代码用到 export class 的是时候,在构造器 contructor(...){...} 中填写了参数,但应用(或者哪怕没用到)该 class 的时候没有填写对应参数,打包编译过程中 compiler 就会报这个错误。

export class DragableOptionsService {
  public name: string = '';
  public isSort: boolean = true;

    /* 如果当前类 DragableOptionsService 有被用到而没用填写对应的参数,或者没有用到,打包编译的时候都会报错 */
  constructor(name: string, isSort: boolean) {
    this.name = name;
    this.isSort = isSort;
  }
}
上一篇 下一篇

猜你喜欢

热点阅读