JS進階特性

來源:互聯網
上載者:User

標籤:style   blog   class   code   c   java   

一、JavaScript的同源策略

參考連結:https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Same_origin_policy_for_JavaScript

同源策略限制了一個源(origin)中載入文本或指令碼與來自其它源(origin)中資源的互動方式。同源定義如果兩個頁面擁有相同的協議(protocol),連接埠(如果指定),和主機,那麼這兩個頁面就屬於同一個源(origin)。下表給出了相對http://store.company.com/dir/page.html同源檢測的樣本:URL    結果    原因http://store.company.com/dir2/other.html    成功     http://store.company.com/dir/inner/another.html    成功     https://store.company.com/secure.html    失敗    協議不同http://store.company.com:81/dir/etc.html    失敗    連接埠不同http://news.company.com/dir/other.html    失敗    主機名稱不同參見origin definition for file: URLs.源繼承來自about:blank,javascript:和data:URLs中的內容,繼承了將其載入的文檔所指定的源,因為它們的URL本身未指定任何關於自身源的資訊。

 

二、自動執行
(function() {    alert(‘haha‘);}());

 

三、閉包
我的理解誒閉包:就是能夠從函數外部讀取函數內部的局部變數
(function() { function foo(x) { var tmp = 3; return function (y) { alert(x + y + (++tmp)); } } var bar = foo(2); // bar 現在是一個閉包 bar(10); //能讀取foo的x和temp變數 bar(10);}());

 

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.