get()
prototype method of the
WebAssembly.Table()
object retrieves a function reference stored at a given index.
table.get(index);
The index of the function reference you want to retrieve.
A function reference — this is an exported WebAssembly function , a JavaScript wrapper for an underlying wasm function.
若
index
is greater than or equal to
Table.prototype.length
,
RangeError
is thrown.
The following example (see
table.html
on GitHub, and
view it live
also) compiles and instantiates the loaded table.wasm byte code using the
WebAssembly.instantiateStreaming()
method. It then retrieves the references stored in the exported table.
WebAssembly.instantiateStreaming(fetch('table.wasm'))
.then(function(obj) {
var tbl = obj.instance.exports.tbl;
console.log(tbl.get(0)()); // 13
console.log(tbl.get(1)()); // 42
});
Note how you've got to include a second function invocation operator at the end of the accessor to actually retrieve the value stored inside the reference (e.g.
get(0)()
而不是
get(0)
) — it is a function rather than a simple value.
| 规范 |
|---|
|
WebAssembly JavaScript 接口
The definition of 'get()' in that specification. |
| Desktop | Mobile | Server | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
get
|
Chrome 57 | Edge 16 |
Firefox
52
|
IE No | Opera 44 | Safari 11 | WebView Android 57 | Chrome Android 57 |
Firefox Android
52
|
Opera Android 43 | Safari iOS 11 | Samsung Internet Android 7.0 | nodejs 8.0.0 |
完整支持
不支持
见实现注意事项。
WebAssembly
WebAssembly.Module
WebAssembly.Global
WebAssembly.Instance
WebAssembly.Memory
WebAssembly.Table
WebAssembly.CompileError
WebAssembly.LinkError
WebAssembly.RuntimeError
Object
Object.prototype.__defineGetter__()
Object.prototype.__defineSetter__()
Object.prototype.__lookupGetter__()
Object.prototype.__lookupSetter__()
Object.prototype.hasOwnProperty()
Object.prototype.isPrototypeOf()
Object.prototype.propertyIsEnumerable()
Object.prototype.toLocaleString()
Object.prototype.toSource()
Object.prototype.toString()
Object.prototype.valueOf()
Object.setPrototypeOf()