[英]A class as an interface in angular typescript
In a component he uses something like: 在组件中,他使用类似以下内容的方法:
Method (Obj: MyClass) { .... }
It's a shorthand for Obj = new MyClass
? 这是Obj = new MyClass
的简写吗?
And if in the constructor of MyClass
there is an argument needed, this should be Obj = new MyClass (argument)
? 并且如果在MyClass
的构造函数中需要一个参数,则应为Obj = new MyClass (argument)
? and the Obj: MyClass
, still works? 和Obj: MyClass
,仍然有效吗?
It's a shorthand for
Obj = new MyClass
? 这是Obj = new MyClass
的简写吗?
No, it is not. 不它不是。 It only specifies that Method
receives an argument ( Obj
reference inside the method) of type MyClass
. 它仅指定Method
接收类型为MyClass
的参数(方法内的Obj
引用)。 It means the argument passed to Method
must be an instance of MyClass
. 这意味着传递给Method
的参数必须是MyClass
的实例。
Example of correct usage of Method
: 正确使用Method
示例:
const ob = new MyClass(); // supose `MyClass` constructor does NOT requieres any argument
Method(ob);
Example of incorrect usage of Method
: 错误使用Method
示例:
Method();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.