相关疑难解决方法(0)

子类化Javascript数组.TypeError:Array.prototype.toString不是通用的

是否可以从javascript数组继承和继承?

我想拥有自己的自定义Array对象,它具有Array的所有功能,但包含其他属性.myobj instanceof CustomArray如果实例是我的CustomArray,我将用于执行特定操作.

在尝试子类化并遇到一些问题后,我发现Dean Edwards的这篇文章指出使用Array对象执行此操作无法正常工作.事实证明,Internet Explorer无法正确处理它.但我也发现了其他问题(目前只在Chrome中测试过).

这是一些示例代码:

/** 
 *  Inherit the prototype methods from one constructor into another 
 *  Borrowed from Google Closure Library 
 */
function inherits(childCtor, parentCtor) {
    function tempCtor() {};
    tempCtor.prototype = parentCtor.prototype;
    childCtor.superClass_ = parentCtor.prototype;
    childCtor.prototype = new tempCtor();
    childCtor.prototype.constructor = childCtor;
},

// Custom class that extends Array class
function CustomArray() {
    Array.apply(this, arguments);
}
inherits(CustomArray,Array);

array = new Array(1,2,3);
custom = new CustomArray(1,2,3);
Run Code Online (Sandbox Code Playgroud)

在Chrome的控制台中输入以下内容即可输出以下内容:

> custom
[]
> array
[1, …
Run Code Online (Sandbox Code Playgroud)

javascript inheritance

34
推荐指数
2
解决办法
2万
查看次数

Angular 8:TypeError:发现不可调用@@iterator

当我发送http get请求时,我收到这些错误TypeError: Found non-callable @@iterator,但它Angular 7不在Angular 8.

我的组件文件
component.ts文件中我调用了服务getCodes()

onSubmit(){
 this.service.getCodes('localhost/Aggregator/getCodes').subscribe (result=>{
 }, error =>{
    console.log(error);
 })
}
Run Code Online (Sandbox Code Playgroud)

我的拦截器文件
当我发送请求时,我已经通过拦截器传递了这些标头

@Injectable()
    export class Interceptor implements HttpInterceptor {
      sessionParam:any = {
        userParam: {
          'a':66,
          'b':101,
          'c':'0201',
          'd':'Y',
          'e':'Y',
          'h':'2019/02/22',
          'f':'Y',
          'g':12
        }
      }

      intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
        let headers = new HttpHeaders();
        for (var val in this.sessionParam) {
          Object.keys(this.sessionParam[val]).forEach(key => {
            headers = headers.append(key,this.sessionParam[val][key]);
          });
        }
        request = …
Run Code Online (Sandbox Code Playgroud)

typescript angular

13
推荐指数
4
解决办法
3万
查看次数

标签 统计

angular ×1

inheritance ×1

javascript ×1

typescript ×1