mirror of
https://github.com/fofolee/uTools-Manuals.git
synced 2026-02-27 09:32:01 +08:00
语法高亮,滚动条美化,设置页面调整
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
<div></div>
|
||||
<p><strong><code>WebAssembly.Global</code></strong> 对象表示一个全局变量实例, 可以被JavaScript 和importable/exportable 访问 ,跨越一个或多个<a href="Reference/Global_Objects/WebAssembly/Module" title="所有 Module 实例继承自 Module() 构造函数的原型对象 —— 修改它会影响所有 Module 实例。"><code>WebAssembly.Module</code></a> 实例. 他允许被多个modules动态连接.</p>
|
||||
<h2 id="构造函数语法">构造函数语法</h2>
|
||||
<pre class="syntaxbox">var myGlobal = new WebAssembly.Global(<em>descriptor</em>, <em>value</em>);</pre>
|
||||
<pre><code class="language-javascript">var myGlobal = new WebAssembly.Global(<em>descriptor</em>, <em>value</em>);</code></pre>
|
||||
<h3 id="参数">参数</h3>
|
||||
<dl>
|
||||
<dt>descriptor</dt>
|
||||
@@ -36,7 +36,7 @@
|
||||
<h2 id="例子">例子</h2>
|
||||
<p>以下例子展示了使用 <code>WebAssembly.Global()</code> 构造函数创建一个新的实例. 它定义为可修饰的 类型为<code>i32</code> , 值为 0.</p>
|
||||
<p>global的值发生改变, 首先设置<code>Global.value</code> 为42, 然后使用导出函数 <code>incGlobal()</code> 增加为43. 导出函数在 <code>global.wasm</code> 模块中(它将参数的值加一并返回).</p>
|
||||
<pre class="brush: js">const output = document.getElementById('output');
|
||||
<pre><code class="language-javascript">const output = document.getElementById('output');
|
||||
|
||||
function assertEq(msg, got, expected) {
|
||||
output.innerHTML += `Testing ${msg}: `;
|
||||
@@ -57,7 +57,7 @@ WebAssembly.instantiateStreaming(fetch('global.wasm'), { js: { global } })
|
||||
assertEq("getting JS-updated value from wasm", instance.exports.getGlobal(), 42);
|
||||
instance.exports.incGlobal();
|
||||
assertEq("getting wasm-updated value from JS", global.value, 43);
|
||||
});</pre>
|
||||
});</code></pre>
|
||||
<div class="note">
|
||||
<p><strong>注意</strong>: 你可以在<a class="external" href="https://mdn.github.io/webassembly-examples/js-api-examples/global.html" rel="noopener">running live on GitHub</a> 查看例子; 也可以访问<a class="external" href="https://github.com/mdn/webassembly-examples/blob/master/js-api-examples/global.html" rel="noopener">source code</a>.</p>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user