aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/mozilla/tech/xpcom/language_bindings/components.utils.cloneinto/index.html
diff options
context:
space:
mode:
Diffstat (limited to 'files/zh-cn/mozilla/tech/xpcom/language_bindings/components.utils.cloneinto/index.html')
-rw-r--r--files/zh-cn/mozilla/tech/xpcom/language_bindings/components.utils.cloneinto/index.html290
1 files changed, 0 insertions, 290 deletions
diff --git a/files/zh-cn/mozilla/tech/xpcom/language_bindings/components.utils.cloneinto/index.html b/files/zh-cn/mozilla/tech/xpcom/language_bindings/components.utils.cloneinto/index.html
deleted file mode 100644
index 0bc55dbf99..0000000000
--- a/files/zh-cn/mozilla/tech/xpcom/language_bindings/components.utils.cloneinto/index.html
+++ /dev/null
@@ -1,290 +0,0 @@
----
-title: Components.utils.cloneInto
-slug: Mozilla/Tech/XPCOM/Language_Bindings/Components.utils.cloneInto
-translation_of: Mozilla/Tech/XPCOM/Language_Bindings/Components.utils.cloneInto
----
-<div><section class="Quick_links" id="Quick_Links">
- <ol>
- <li><a href="/zh-CN/docs/Mozilla/Add-ons/WebExtensions"><strong>Browser extensions</strong></a></li>
- <li class="toggle">
- <details>
- <summary>Getting started</summary>
- <ol>
- <li><a href="/zh-CN/docs/Mozilla/Add-ons/WebExtensions/What_are_WebExtensions">What are extensions?</a></li>
- <li><a href="/zh-CN/docs/Mozilla/Add-ons/WebExtensions/Your_first_WebExtension">Your first extension</a></li>
- <li><a href="/zh-CN/docs/Mozilla/Add-ons/WebExtensions/Your_second_WebExtension">Your second extension</a></li>
- <li><a href="/zh-CN/docs/Mozilla/Add-ons/WebExtensions/Anatomy_of_a_WebExtension">Anatomy of an extension</a></li>
- <li><a href="/zh-CN/docs/Mozilla/Add-ons/WebExtensions/Examples">Example extensions</a></li>
- <li><a href="/zh-CN/docs/Mozilla/Add-ons/WebExtensions/What_next_">What next?</a></li>
- </ol>
- </details>
- </li>
- <li class="toggle">
- <details>
- <summary>Concepts</summary>
- <ol>
- <li><a href="/zh-CN/docs/Mozilla/Add-ons/WebExtensions/Using_the_JavaScript_APIs">Using the JavaScript APIs</a></li>
- <li><a href="/zh-CN/docs/Mozilla/Add-ons/WebExtensions/Content_scripts">Content scripts</a></li>
- <li><a href="/zh-CN/docs/Mozilla/Add-ons/WebExtensions/Match_patterns">Match patterns</a></li>
- <li><a href="/zh-CN/docs/Mozilla/Add-ons/WebExtensions/Working_with_files">Working with files</a></li>
- <li><a href="/zh-CN/docs/Mozilla/Add-ons/WebExtensions/Internationalization">Internationalization</a></li>
- <li><a href="/zh-CN/docs/Mozilla/Add-ons/WebExtensions/Security_best_practices">Security best practices</a></li>
- <li><a href="/zh-CN/docs/Mozilla/Add-ons/WebExtensions/Content_Security_Policy">Content Security Policy</a></li>
- <li><a href="/zh-CN/docs/Mozilla/Add-ons/WebExtensions/Native_messaging">Native messaging</a></li>
- </ol>
- </details>
- </li>
- <li class="toggle">
- <details>
- <summary>User interface</summary>
- <ol>
- <li><a href="/zh-CN/docs/Mozilla/Add-ons/WebExtensions/user_interface">User Interface</a></li>
- <li><a href="/zh-CN/docs/Mozilla/Add-ons/WebExtensions/user_interface/Browser_action">Toolbar button</a></li>
- <li><a href="/zh-CN/docs/Mozilla/Add-ons/WebExtensions/user_interface/Page_actions">Address bar button</a></li>
- <li><a href="/zh-CN/docs/Mozilla/Add-ons/WebExtensions/user_interface/Sidebars">Sidebars</a></li>
- <li><a href="/zh-CN/docs/Mozilla/Add-ons/WebExtensions/user_interface/Context_menu_items">Context menu items</a></li>
- <li><a href="/zh-CN/docs/Mozilla/Add-ons/WebExtensions/user_interface/Options_pages">Options page</a></li>
- <li><a href="/zh-CN/docs/Mozilla/Add-ons/WebExtensions/user_interface/Extension_pages">Extension pages</a></li>
- <li><a href="/zh-CN/docs/Mozilla/Add-ons/WebExtensions/user_interface/Notifications">Notifications</a></li>
- <li><a href="/zh-CN/docs/Mozilla/Add-ons/WebExtensions/user_interface/Omnibox">Address bar suggestions</a></li>
- <li><a href="/zh-CN/docs/Mozilla/Add-ons/WebExtensions/user_interface/devtools_panels">Developer tools panels</a></li>
- </ol>
- </details>
- </li>
- <li class="toggle">
- <details>
- <summary>How to</summary>
- <ol>
- <li><a href="/zh-CN/docs/Mozilla/Add-ons/WebExtensions/Intercept_HTTP_requests">Intercept HTTP requests</a></li>
- <li><a href="/zh-CN/docs/Mozilla/Add-ons/WebExtensions/Modify_a_web_page">Modify a web page</a></li>
- <li><a href="/zh-CN/docs/Mozilla/Add-ons/WebExtensions/Safely_inserting_external_content_into_a_page">Insert external content</a></li>
- <li><a href="/zh-CN/docs/Mozilla/Add-ons/WebExtensions/Add_a_button_to_the_toolbar">Add a button to the toolbar</a></li>
- <li><a href="/zh-CN/docs/Mozilla/Add-ons/WebExtensions/Implement_a_settings_page">Implement a settings page</a></li>
- <li><a href="/zh-CN/docs/Mozilla/Add-ons/WebExtensions/Working_with_the_Tabs_API">Work with the Tabs API</a></li>
- <li><a href="/zh-CN/docs/Mozilla/Add-ons/WebExtensions/Work_with_the_Bookmarks_API">Work with the Bookmarks API</a></li>
- <li><a href="/zh-CN/docs/Mozilla/Add-ons/WebExtensions/Work_with_the_Cookies_API">Work with the Cookies API</a></li>
- <li><a href="/zh-CN/docs/Mozilla/Add-ons/WebExtensions/Work_with_contextual_identities">Work with contextual identities</a></li>
- <li><a href="/zh-CN/docs/Mozilla/Add-ons/WebExtensions/onboarding_upboarding_offboarding_best_practices">Onboard, upboard, and offboard users</a></li>
- </ol>
- </details>
- </li>
- <li class="toggle">
- <details>
- <summary>Porting</summary>
- <ol>
- <li><a href="/zh-CN/docs/Mozilla/Add-ons/WebExtensions/Firefox_differentiators">Firefox differentiators</a></li>
- <li><a href="/zh-CN/docs/Mozilla/Add-ons/WebExtensions/Porting_a_Google_Chrome_extension">Porting a Google Chrome extension</a></li>
- <li><a href="/zh-CN/docs/Mozilla/Add-ons/WebExtensions/Porting_a_legacy_Firefox_add-on">Porting a legacy Firefox extension</a></li>
- <li><a href="/zh-CN/docs/Mozilla/Add-ons/WebExtensions/Embedded_WebExtensions">Embedded WebExtensions</a></li>
- <li><a href="/zh-CN/docs/Mozilla/Add-ons/WebExtensions/Comparison_with_the_Add-on_SDK">Comparison with the Add-on SDK</a></li>
- <li><a href="/zh-CN/docs/Mozilla/Add-ons/WebExtensions/Comparison_with_XUL_XPCOM_extensions">Comparison with XUL/XPCOM extensions</a></li>
- <li><a href="/zh-CN/docs/Mozilla/Add-ons/WebExtensions/Differences_between_API_implementations">Differences between API implementations</a></li>
- <li><a href="/zh-CN/docs/Mozilla/Add-ons/WebExtensions/Chrome_incompatibilities">Chrome incompatibilities</a></li>
- <li><a href="/zh-CN/docs/Mozilla/Add-ons/WebExtensions/Differences_between_desktop_and_Android">Differences between desktop and Android</a></li>
- </ol>
- </details>
- </li>
- <li class="toggle">
- <details>
- <summary>Firefox workflow</summary>
- <ol>
- <li><a href="/zh-CN/docs/Mozilla/Add-ons/WebExtensions/Development_Tools">Developer tools</a></li>
- <li><a href="/zh-CN/docs/Mozilla/Add-ons/WebExtensions/User_experience_best_practices">User Experience</a></li>
- <li><a href="/zh-CN/docs/Mozilla/Add-ons/WebExtensions/Temporary_Installation_in_Firefox">Temporary Installation in Firefox</a></li>
- <li><a href="/zh-CN/docs/Mozilla/Add-ons/WebExtensions/Debugging">Debugging</a></li>
- <li><a href="/zh-CN/docs/Mozilla/Add-ons/WebExtensions/Testing_persistent_and_restart_features">Testing persistent and restart features</a></li>
- <li><a href="/zh-CN/docs/Mozilla/Add-ons/WebExtensions/Developing_WebExtensions_for_Firefox_for_Android">Developing for Firefox for Android</a></li>
- <li><a href="/zh-CN/docs/Mozilla/Add-ons/WebExtensions/Getting_started_with_web-ext">Getting started with web-ext</a></li>
- <li><a href="/zh-CN/docs/Mozilla/Add-ons/WebExtensions/web-ext_command_reference">web-ext command reference</a></li>
- <li><a href="/zh-CN/docs/Mozilla/Add-ons/WebExtensions/WebExtensions_and_the_Add-on_ID">Extensions and the Add-on ID</a></li>
- <li><a href="/zh-CN/docs/Mozilla/Add-ons/WebExtensions/Request_the_right_permissions">Request the right permissions</a></li>
- </ol>
- </details>
- </li>
- <li class="toggle">
- <details>
- <summary>JavaScript APIs</summary>
- <ol><li><a href="/zh-CN/docs/Mozilla/Add-ons/WebExtensions/Browser_support_for_JavaScript_APIs">Browser support for JavaScript APIs</a></li><li><a href="/zh-CN/docs/Mozilla/Add-ons/WebExtensions/API/alarms">alarms</a></li><li><a href="/zh-CN/docs/Mozilla/Add-ons/WebExtensions/API/bookmarks">bookmarks</a></li><li><a href="/zh-CN/docs/Mozilla/Add-ons/WebExtensions/API/browserAction">browserAction</a></li><li><a href="/zh-CN/docs/Mozilla/Add-ons/WebExtensions/API/contextMenus">contextMenus</a></li><li><a href="/zh-CN/docs/Mozilla/Add-ons/WebExtensions/API/cookies">cookies</a></li><li><a href="/zh-CN/docs/Mozilla/Add-ons/WebExtensions/API/devtools.inspectedWindow">devtools.inspectedWindow</a></li><li><a href="/zh-CN/docs/Mozilla/Add-ons/WebExtensions/API/history">history</a></li><li><a href="/zh-CN/docs/Mozilla/Add-ons/WebExtensions/API/runtime">runtime</a></li><li><a href="/zh-CN/docs/Mozilla/Add-ons/WebExtensions/API/storage">storage</a></li><li><a href="/zh-CN/docs/Mozilla/Add-ons/WebExtensions/API/tabs">tabs</a></li><li><a href="/zh-CN/docs/Mozilla/Add-ons/WebExtensions/API/webNavigation">webNavigation</a></li><li><a href="/zh-CN/docs/Mozilla/Add-ons/WebExtensions/API/webRequest">webRequest</a></li><li><a href="/zh-CN/docs/Mozilla/Add-ons/WebExtensions/API/windows">windows</a></li></ol>
- </details>
- </li>
-
- <li class="toggle">
- <details>
- <summary>Manifest keys</summary>
- <ol><li><a href="/zh-CN/docs/Mozilla/Add-ons/WebExtensions/manifest.json/browser_specific_settings">applications</a></li><li><a href="/zh-CN/docs/Mozilla/Add-ons/WebExtensions/manifest.json/browser_action">browser_action</a></li><li><a href="/zh-CN/docs/Mozilla/Add-ons/WebExtensions/manifest.json/content_scripts">content_scripts</a></li><li><a href="/zh-CN/docs/Mozilla/Add-ons/WebExtensions/manifest.json/default_locale">default_locale</a></li><li><a href="/zh-CN/docs/Mozilla/Add-ons/WebExtensions/manifest.json/developer">developer</a></li><li><a href="/zh-CN/docs/Mozilla/Add-ons/WebExtensions/manifest.json/manifest_version">manifest_version</a></li><li><a href="/zh-CN/docs/Mozilla/Add-ons/WebExtensions/manifest.json/version">version</a></li><li><a href="/zh-CN/docs/Mozilla/Add-ons/WebExtensions/manifest.json/%E4%B8%BB%E9%A1%B5%E5%9C%B0%E5%9D%80">主页地址</a></li><li><a href="/zh-CN/docs/Mozilla/Add-ons/WebExtensions/manifest.json/author">作者 - author</a></li><li><a href="/zh-CN/docs/Mozilla/Add-ons/WebExtensions/manifest.json/name">名称 - name</a></li><li><a href="/zh-CN/docs/Mozilla/Add-ons/WebExtensions/manifest.json/background">后台 - background</a></li><li><a href="/zh-CN/docs/Mozilla/Add-ons/WebExtensions/manifest.json/description">描述 - description</a></li><li><a href="/zh-CN/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions">权限 - permissions</a></li><li><a href="/zh-CN/docs/Mozilla/Add-ons/WebExtensions/manifest.json/short_name">短名称 - short_name</a></li></ol>
- </details>
- </li>
-
- <li><a href="/zh-CN/docs/Mozilla/Add-ons/Themes"><strong>Themes</strong></a></li>
- <li class="toggle">
- <details>
- <summary>Browser themes</summary>
- <ol>
- <li><a href="/zh-CN/docs/Mozilla/Add-ons/Themes/Theme_concepts">Browser theme concepts</a></li>
- </ol>
- </details>
- </li>
- <li><a href="/zh-CN/docs/Mozilla/Add-ons/Distribution"><strong>Publishing and Distribution</strong></a></li>
- <li class="toggle">
- <details>
- <summary>Publishing add-ons</summary>
- <ol>
- <li><a href="/zh-CN/docs/Mozilla/Add-ons/Distribution">Signing and distribution overview</a></li>
- <li><a href="/zh-CN/docs/Mozilla/Add-ons/WebExtensions/Package_your_extension_">Package your extension</a></li>
- <li><a href="/zh-CN/docs/Mozilla/Add-ons/Distribution/Submitting_an_add-on">Submit an add-on</a></li>
- <li><a href="/zh-CN/docs/Mozilla/Add-ons/Source_Code_Submission">Source code submission</a></li>
- <li><a href="/zh-CN/docs/Mozilla/Add-ons/Distribution/Resources_for_publishers">Resources for publishers</a></li>
- <li><a href="/zh-CN/docs/Mozilla/Add-ons/Listing">Creating an appealing listing</a></li>
- <li><a href="/zh-CN/docs/Mozilla/Add-ons/Distribution/Make_money_from_browser_extensions">Make money from browser extensions</a></li>
- <li><a href="/zh-CN/docs/Mozilla/Add-ons/Distribution/Promoting_your_extension_or_theme">Promoting your extension or theme</a></li>
- <li><a href="/zh-CN/docs/Mozilla/Add-ons/AMO/Policy/Reviews">Review policies</a></li>
- <li><a href="/zh-CN/docs/Mozilla/Add-ons/AMO/Policy/Agreement">Developer agreement</a></li>
- <li><a href="/zh-CN/docs/Mozilla/Add-ons/AMO/Policy/Featured">Featured add-ons</a></li>
- <li><a href="/zh-CN/docs/Mozilla/Add-ons/Distribution/Retiring_your_extension">Retiring your extension</a></li>
- </ol>
- </details>
- </li>
- <li class="toggle">
- <details>
- <summary>Distributing add-ons</summary>
- <ol>
- <li><a href="/zh-CN/docs/Mozilla/Add-ons/WebExtensions/Alternative_distribution_options/Sideloading_add-ons">For sideloading</a></li>
- <li><a href="/zh-CN/docs/Mozilla/Add-ons/WebExtensions/Alternative_distribution_options/Add-ons_for_desktop_apps">For desktop apps</a></li>
- <li><a href="/zh-CN/docs/Mozilla/Add-ons/WebExtensions/Alternative_distribution_options/Add-ons_in_the_enterprise">For an enterprise</a></li>
- </ol>
- </details>
- </li>
- <li><a href="https://discourse.mozilla.org/c/add-ons"><strong>Community and Support</strong></a></li>
- <li class="toggle">
- <details>
- <summary>Channels</summary>
- <ol>
- <li><a href="https://blog.mozilla.org/addons">Add-ons blog</a></li>
- <li><a href="https://discourse.mozilla.org/c/add-ons">Add-on forums</a></li>
- <li><a href="http://stackoverflow.com/questions/tagged/firefox-addon">Stack Overflow</a></li>
- <li><a href="/zh-CN/docs/Mozilla/Add-ons/#Contact_us">Contact us</a></li>
- </ol>
- </details>
- </li>
- </ol>
-</section></div>
-
-<p><span class="seoSummary">该函数为定义在某一作用域中的对象提供了一个安全的、将其<a href="https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/The_structured_clone_algorithm">结构化克隆</a>到其字作用域中的方法,</span>并返回对克隆对象的引用:</p>
-
-<pre class="brush: js">var clonedObject = cloneInto(myObject, targetWindow);</pre>
-
-<p>可以将克隆后的对象作为可扩展对象的动态属性引入到特定作用域中,以便运行在该作用域的脚本进行访问:</p>
-
-<pre class="brush: js">targetWindow.foo = clonedObject;</pre>
-
-<p>通过这种方式,运行在某一作用域中的代码可以和运行在另一作用域中的代码共享对某一对象的访问。</p>
-
-<h2 id="语法">语法</h2>
-
-<pre class="brush: js">Components.utils.cloneInto(obj, targetScope[, options]);</pre>
-
-<h3 id="参数列表">参数列表</h3>
-
-<dl>
- <dt><code>obj : object</code></dt>
- <dd>被克隆对象。</dd>
- <dt><code>targetScope : object</code></dt>
- <dd>对象克隆后的容器。</dd>
- <dt><code>options : object</code></dt>
- <dd>该参数为一可选参数。该参数为一拥有以下可选属性的对象:</dd>
-</dl>
-
-<ul>
- <li><code>cloneFunctions</code>: 决定函数是否被克隆的布尔值。默认值为 <code>false</code>。Cloned functions have the same semantics as functions exported using <a href="/en-US/docs/Components.utils.exportFunction"><code>Components.utils.exportFunction</code></a>. See <a href="/en-US/docs/Components.utils.cloneInto#Cloning_objects_that_have_functions">Cloning objects that have functions</a> below.</li>
- <li><code>wrapReflectors</code>: a Boolean value that determines if objects reflected from C++, such as DOM objects, should be cloned. If omitted the default value is <code>false</code>. See <a href="/en-US/docs/Components.utils.cloneInto#Cloning_objects_that_contain_DOM_elements">Cloning objects that contain DOM elements</a> below.</li>
-</ul>
-
-<h3 id="返回值">返回值</h3>
-
-<p>对克隆后的对象的引用。</p>
-
-<h2 id="范例">范例</h2>
-
-<p>This add-on script creates an object, clones it into the content window and makes it a property of the content window global:</p>
-
-<pre class="brush: js">// add-on script
-
-var addonScriptObject = {"greeting" : "hello from add-on"};
-contentWindow.addonScriptObject = cloneInto(addonScriptObject, contentWindow);</pre>
-
-<p>Scripts running in the page can now access the object:</p>
-
-<pre class="brush: js">// page script
-
-button.addEventListener("click", function() {
- console.log(window.addonScriptObject.greeting); // "hello from add-on"
-}, false);</pre>
-
-<p>Of course, you don't have to assign the clone to the window itself: you can assign it to some other object in the target scope:</p>
-
-<pre class="brush: js">contentWindow.foo.addonScriptObject = cloneInto(addonScriptObject, contentWindow);</pre>
-
-<p>You can also pass it into a function defined in the page script. Suppose the page script defines a function like this:</p>
-
-<pre class="brush: js">// page script
-
-function foo(greeting) {
- console.log("they said: " + greeting.message);
-}
-</pre>
-
-<p>The add-on script can define an object, clone it, and pass it into this function:</p>
-
-<pre class="brush: js">// add-on script
-
-var addonScriptObject = {"message" : "hello from add-on"};
-contentWindow.foo(cloneInto(addonScriptObject, contentWindow)); // "they said: hello from add-on"</pre>
-
-<h3 id="Cloning_objects_that_have_functions">Cloning objects that have functions</h3>
-
-<p>If the object to be cloned contains functions, you must pass the <code>{cloneFunctions:true}</code> flag or you'll get an error. If you do pass this flag, then functions in the object are cloned using the same mechanism as that used in <a href="/en-US/docs/Components.utils.exportFunction"><code>Components.utils.exportFunction</code></a>:</p>
-
-<pre class="brush: js">// add-on script
-
-var addonScriptObject = {
- greetme: function() {
- alert("hello from add-on");
- }
-};
-
-contentWindow.addonScriptObject = cloneInto(addonScriptObject,
- contentWindow,
- {cloneFunctions: true});
-</pre>
-
-<pre class="brush: js">// page script
-
-var test = document.getElementById("test");
-
-test.addEventListener("click", function() {
- window.addonScriptObject.greetme();
-}, false);</pre>
-
-<h3 id="Cloning_objects_that_contain_DOM_elements">Cloning objects that contain DOM elements</h3>
-
-<p>By default, if the object you clone contains objects that are reflected from C++, such as DOM elements, the cloning operation will fail with an error. If you pass the <code>{wrapReflectors:true}</code> flag, then the object you clone is allowed to contain these objects:</p>
-
-<pre class="brush: js">// add-on script
-
-var addonScriptObject = {
- body: contentWindow.document.body
-};
-
-contentWindow.addonScriptObject = cloneInto(addonScriptObject,
- contentWindow,
- {wrapReflectors: true});</pre>
-
-<pre class="brush: js">// page script
-
-var test = document.getElementById("test");
-
-test.addEventListener("click", function() {
- console.log(window.addonScriptObject.body.innerHTML);
-}, false);</pre>
-
-<p>Access to these objects in the target scope is subject to the normal <a href="/en-US/docs/Security_check_basics">security checks</a>.</p>