Array和Observable Array有什么区别? [英] What is the difference between an Array and an Observable Array?
问题描述
在TypeScript中, any []
和 Observable< any [])>
之间的主要区别是什么? ?
使用它们的缺点和优点是什么?
In TypeScript, what is the main difference between any[]
and Observable<any[])>
?
What are the cons and pros of using each of them?
推荐答案
Observable用于实现观察者模式。您可以订阅此Observable,并在Observable发出数据时发现异步。
Observables are used for implementing the Observer pattern. You can subscribe this Observable and you getting asynchrounous noticed when the Observable emit data.
Observable< any [])
是 Obervable ,其中包含一个数组。在这种情况下,数组可以包含任何类型,因为它是由任何键入的。
Observable<any[])
is Obervable which contains an array. In this case, the array can contain any type, since it is typed by any.
数组是只有一个对象,一次可以容纳多个值。
A array is only an object, which can hold more than one value at a time.
Observable对象表示基于推送的集合。
The Observable object represents a push based collection.
观察者和观察者接口为基于推送的通知提供了一个通用机制
,也称为观察者设计
模式。 Observable对象表示发送
通知的对象(提供者); Observer对象表示接收它们的类
(观察者)。
The Observer and Observable interfaces provide a generalized mechanism for push-based notification, also known as the observer design pattern. The Observable object represents the object that sends notifications (the provider); the Observer object represents the class that receives them (the observer).
vs。
数组是类似列表的对象,其原型具有执行遍历和变异操作的方法。 JavaScript数组的长度及其元素的类型都不固定。
Arrays are list-like objects whose prototype has methods to perform traversal and mutation operations. Neither the length of a JavaScript array nor the types of its elements are fixed.
这篇关于Array和Observable Array有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!