浏览器 API 返回的对象是常量吗?
Are objects, which are returned by browser APIs, const?
考虑一个 Position 对象,我可以通过 API 调用获得它。
如果我多次调用 API,API return 每次都会调用相同的(单例)位置对象,在它之后 edits/updates 对象的 属性值?或者它会每次实例化并return一个新对象吗?
即如果我存储 Position 对象,下一个 API 调用是否会覆盖 stored/old 值?为了避免这种可能性,一定要clone/copy吗?
此行为是否在某处定义(针对所有 API 或每个 API)?
我猜 API(以及所有 API)return 是新对象,但我想知道我是否可以依赖它。
API 规范应该告诉您会发生什么。例如getCurrentPosition
(强调我的):
When called, it must immediately return and then asynchronously attempt to obtain the current location of the device. If the attempt is successful, the successCallback
must be invoked (i.e. the handleEvent
operation must be called on the callback object) with a new Position
object, reflecting the current location of the device.
考虑一个 Position 对象,我可以通过 API 调用获得它。
如果我多次调用 API,API return 每次都会调用相同的(单例)位置对象,在它之后 edits/updates 对象的 属性值?或者它会每次实例化并return一个新对象吗?
即如果我存储 Position 对象,下一个 API 调用是否会覆盖 stored/old 值?为了避免这种可能性,一定要clone/copy吗?
此行为是否在某处定义(针对所有 API 或每个 API)?
我猜 API(以及所有 API)return 是新对象,但我想知道我是否可以依赖它。
API 规范应该告诉您会发生什么。例如getCurrentPosition
(强调我的):
When called, it must immediately return and then asynchronously attempt to obtain the current location of the device. If the attempt is successful, the
successCallback
must be invoked (i.e. thehandleEvent
operation must be called on the callback object) with a newPosition
object, reflecting the current location of the device.