英文:
How do I check if a value is a `SharedArrayBuffer` view, in Javascript?
问题
ArrayBuffer.isView() 静态方法 用于检查它是否是 ArrayBuffer 视图,例如 TypedArray 对象或 DataView。
要检查是否是 SharedArrayBuffer 视图,你应该如何操作?
自从引入 SharedArrayBuffer 以来已经过了相当长的时间,然
英文:
The ArrayBuffer.isView() static method checks if it's one of the ArrayBuffer views, such as TypedArray objects or a DataView.
How do you check if it's a view of a SharedArrayBuffer?
It's been a quite long time since SharedArrayBuffer was introduced, yet oddly, nobody's talking about the SharedArrayBuffer counterpart of the ArrayBuffer.isView method. Or, is it that I can use ArrayBuffer.isView to check for SharedArrayBuffer views as well?
I've read https://stackoverflow.com/q/15251879/4510033 but this question seems to be specifically focusing on ArrayBuffers, not SharedArrayBuffers.
答案1
得分: 0
你可以在视图的 .buffer 属性上使用 instanceof:
view.buffer instanceof SharedArrayBuffer
如果你不确定对象是否是任何缓冲区上的视图,请首先使用 ArrayBuffer.isView(view)。
英文:
You can use instanceof on the .buffer property of the view:
view.buffer instanceof SharedArrayBuffer
If you are not certain whether the object is a view on any buffer at all, use ArrayBuffer.isView(view) first.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论