最近我想在我的angular 4应用程序中实现观察者模式,我在打字稿中遇到了这种代码语法,我不知道这意味着什么?
代码:
module Patterns.Interfaces {
export interface IObservable {
RegisterObserver(Observer: Patterns.Interfaces.IObserver);//Patterns.Interfaces.IObserver type?
RemoveObserver(Observer: Patterns.Interfaces.IObserver);
NotifyObservers();
}
}
感谢您的帮助。
答案 0 :(得分:5)
这是一个带注释的版本:
// There's a namespace named Patterns.Interfaces
module Patterns.Interfaces {
// It has an interface named IObservable
// It is visible outside this block ('export')
export interface IObservable {
// An IObservable has a function called RegisterObserver.
// It takes one argument named 'Observer'.
// 'Observer' is of type Pattern.Interfaces.IObserver.
// You must pass this argument.
// Its return type is unspecified, so is assumed to be 'any'
RegisterObserver(Observer: Patterns.Interfaces.IObserver);//Patterns.Interfaces.IObserver type?
// Same as above
RemoveObserver(Observer: Patterns.Interfaces.IObserver);
// An IObservable has a function called NotifyObservers.
// It is called with no arguments.
// Its return type is unspecified, so is assumed to be 'any'
NotifyObservers();
}
}