2016-05-04 7 views
0

私は拡張クラスを呼び出して、それがまだ必要なものをインポートしてもらえますか?ES6拡張クラスで挿入する

ようこそクラス:

import { ErrorLevel } from './error-level.js'; 

export class Welcome extends ErrorLevel { 
    constructor() { 
    super(); 
    } 
} 

エラーレベルのクラス:

import { Notification } from 'aurelia-notification'; 

export class ErrorLevel { 
    static inject() { 
    return [Notification]; 
    } 

    constructor(notification) { 
    this.notification = notification; 
    } 
} 

私が知っているが、一度私はそれが拡張したクラスを呼び出し、0の引数に渡しますsuper()を呼び出します。 super()を呼び出すと、私のErrorClassコンストラクタが通知を引き出す方法はありますか?ようこそさんsuper機能に引数を渡す

+1

方法。 } '? – Bergi

+0

私はこのことを知っていました。ウェルカムクラスに通知を注入してから、それを拡張クラスに渡しました。その周りに道があるかどうか疑問に思っていた – allencoded

+0

とにかくここに何か「注入」しているのは誰ですか? – Bergi

答えて

0

super([arguments]); // calls the parent constructor. super.functionOnParent([arguments]);

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/super

は、その引数を持つ親クラスのコンストラクタを呼び出します。 thisのログには、スーパーに渡す引数に設定されている通知が含まれています。 `コンストラクタ(通知){スーパー(通知)について

http://jsbin.com/raguqopesu/1/edit?js,console,output

class ErrorLevel { 
    constructor(notification) { 
    this.notification = notification; 
    } 
} 


class Welcome extends ErrorLevel { 
    constructor() { 
    super(Notification); 
    console.log(this); 
    } 
} 


const yo = new Welcome(); 
0
export class Welcome extends ErrorLevel { 
    constructor(notification) { 
    super(notification); 
    } 
} 
関連する問題