{"id":414,"date":"2020-02-14T14:13:48","date_gmt":"2020-02-14T06:13:48","guid":{"rendered":"https:\/\/blog.cqdefxxx.com\/?p=414"},"modified":"2020-02-14T14:13:48","modified_gmt":"2020-02-14T06:13:48","slug":"%e5%87%bd%e6%95%b0","status":"publish","type":"post","link":"https:\/\/blog.viter.top\/index.php\/2020\/02\/14\/%e5%87%bd%e6%95%b0\/","title":{"rendered":"\u51fd\u6570"},"content":{"rendered":"<pre class=\"pure-highlightjs\"><code class=\"\">&lt;!DOCTYPE html&gt;\n&lt;html lang=\"en\"&gt;\n&lt;head&gt;\n  &lt;meta charset=\"UTF-8\"&gt;\n  &lt;title&gt;04_\u51fd\u6570&lt;\/title&gt;\n&lt;\/head&gt;\n&lt;body&gt;\n&lt;!--\n1. \u4ec0\u4e48\u662f\u51fd\u6570?\n  * \u5b9e\u73b0\u7279\u5b9a\u529f\u80fd\u7684n\u6761\u8bed\u53e5\u7684\u5c01\u88c5\u4f53\n  * \u53ea\u6709\u51fd\u6570\u662f\u53ef\u4ee5\u6267\u884c\u7684, \u5176\u5b83\u7c7b\u578b\u7684\u6570\u636e\u4e0d\u80fd\u6267\u884c\n2. \u4e3a\u4ec0\u4e48\u8981\u7528\u51fd\u6570?\n  * \u63d0\u9ad8\u4ee3\u7801\u590d\u7528\n  * \u4fbf\u4e8e\u9605\u8bfb\u4ea4\u6d41\n3. \u5982\u4f55\u5b9a\u4e49\u51fd\u6570?\n  * \u51fd\u6570\u58f0\u660e\n  * \u8868\u8fbe\u5f0f\n4. \u5982\u4f55\u8c03\u7528(\u6267\u884c)\u51fd\u6570?\n  * test(): \u76f4\u63a5\u8c03\u7528\n  * obj.test(): \u901a\u8fc7\u5bf9\u8c61\u8c03\u7528\n  * new test(): new\u8c03\u7528\n  * test.call\/apply(obj): \u4e34\u65f6\u8ba9test\u6210\u4e3aobj\u7684\u65b9\u6cd5\u8fdb\u884c\u8c03\u7528\n--&gt;\n&lt;script type=\"text\/javascript\"&gt;\n  \/*\n  \u7f16\u5199\u7a0b\u5e8f\u5b9e\u73b0\u4ee5\u4e0b\u529f\u80fd\u9700\u6c42:\n    1. \u6839\u636e\u5e74\u9f84\u8f93\u51fa\u5bf9\u5e94\u7684\u4fe1\u606f\n    2. \u5982\u679c\u5c0f\u4e8e18, \u8f93\u51fa: \u672a\u6210\u5e74, \u518d\u7b49\u7b49!\n    3. \u5982\u679c\u5927\u4e8e60, \u8f93\u51fa: \u7b97\u4e86\u5427!\n    4. \u5176\u5b83, \u8f93\u51fa: \u521a\u597d!\n  *\/\n  function showInfo (age) {\n    if(age&lt;18) {\n      console.log('\u672a\u6210\u5e74, \u518d\u7b49\u7b49!')\n    } else if(age&gt;60) {\n      console.log('\u7b97\u4e86\u5427!')\n    } else {\n      console.log('\u521a\u597d!')\n    }\n  }\n\n  showInfo(17)\n  showInfo(20)\n  showInfo(65)\n\n  function fn1 () { \/\/\u51fd\u6570\u58f0\u660e\n    console.log('fn1()')\n  }\n  var fn2 = function () { \/\/\u8868\u8fbe\u5f0f\n    console.log('fn2()')\n  }\n\n  fn1()\n  fn2()\n\n  var obj = {}\n  function test2 () {\n    this.xxx = 'atguigu'\n  }\n  \/\/ obj.test2()  \u4e0d\u80fd\u76f4\u63a5, \u6839\u672c\u5c31\u6ca1\u6709\n  test2.call(obj) \/\/ obj.test2()   \/\/ \u53ef\u4ee5\u8ba9\u4e00\u4e2a\u51fd\u6570\u6210\u4e3a\u6307\u5b9a\u4efb\u610f\u5bf9\u8c61\u7684\u65b9\u6cd5\u8fdb\u884c\u8c03\u7528\n  console.log(obj.xxx)\n\n&lt;\/script&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;\n\n<\/code><\/pre>\n<pre class=\"pure-highlightjs\"><code class=\"\">&lt;!DOCTYPE html&gt;\n&lt;html lang=\"en\"&gt;\n&lt;head&gt;\n  &lt;meta charset=\"UTF-8\"&gt;\n  &lt;title&gt;05_\u56de\u8c03\u51fd\u6570&lt;\/title&gt;\n&lt;\/head&gt;\n&lt;body&gt;\n&lt;button id=\"btn\"&gt;\u6d4b\u8bd5\u70b9\u51fb\u4e8b\u4ef6&lt;\/button&gt;\n&lt;!--\n1. \u4ec0\u4e48\u51fd\u6570\u624d\u662f\u56de\u8c03\u51fd\u6570?\n  1). \u4f60\u5b9a\u4e49\u7684\n  2). \u4f60\u6ca1\u6709\u8c03\n  3). \u4f46\u6700\u7ec8\u5b83\u6267\u884c\u4e86(\u5728\u67d0\u4e2a\u65f6\u523b\u6216\u67d0\u4e2a\u6761\u4ef6\u4e0b)\n2. \u5e38\u89c1\u7684\u56de\u8c03\u51fd\u6570?\n  * dom\u4e8b\u4ef6\u56de\u8c03\u51fd\u6570 ==&gt;\u53d1\u751f\u4e8b\u4ef6\u7684dom\u5143\u7d20\n  * \u5b9a\u65f6\u5668\u56de\u8c03\u51fd\u6570 ===&gt;window\n\n  * ajax\u8bf7\u6c42\u56de\u8c03\u51fd\u6570(\u540e\u9762\u8bb2)\n  * \u751f\u547d\u5468\u671f\u56de\u8c03\u51fd\u6570(\u540e\u9762\u8bb2)\n--&gt;\n&lt;script type=\"text\/javascript\"&gt;\n  document.getElementById('btn').onclick = function () { \/\/ dom\u4e8b\u4ef6\u56de\u8c03\u51fd\u6570\n    alert(this.innerHTML)\n  }\n\n  \/\/\u5b9a\u65f6\u5668\n    \/\/ \u8d85\u65f6\u5b9a\u65f6\u5668\n    \/\/ \u5faa\u73af\u5b9a\u65f6\u5668\n  setTimeout(function () { \/\/ \u5b9a\u65f6\u5668\u56de\u8c03\u51fd\u6570\n\n    alert('\u5230\u70b9\u4e86'+this)\n  }, 2000)\n\n  \/*var a = 3\n  alert(window.a)\n  window.b = 4\n  alert(b)*\/\n&lt;\/script&gt;\n\n&lt;\/body&gt;\n&lt;\/html&gt;<\/code><\/pre>\n<pre class=\"pure-highlightjs\"><code class=\"\">&lt;!DOCTYPE html&gt;\n&lt;html lang=\"en\"&gt;\n&lt;head&gt;\n  &lt;meta charset=\"UTF-8\"&gt;\n  &lt;title&gt;07_\u51fd\u6570\u4e2d\u7684this&lt;\/title&gt;\n&lt;\/head&gt;\n&lt;body&gt;\n&lt;!--\n1. this\u662f\u4ec0\u4e48?\n  * \u4efb\u4f55\u51fd\u6570\u672c\u8d28\u4e0a\u90fd\u662f\u901a\u8fc7\u67d0\u4e2a\u5bf9\u8c61\u6765\u8c03\u7528\u7684,\u5982\u679c\u6ca1\u6709\u76f4\u63a5\u6307\u5b9a\u5c31\u662fwindow\n  * \u6240\u6709\u51fd\u6570\u5185\u90e8\u90fd\u6709\u4e00\u4e2a\u53d8\u91cfthis\n  * \u5b83\u7684\u503c\u662f\u8c03\u7528\u51fd\u6570\u7684\u5f53\u524d\u5bf9\u8c61\n2. \u5982\u4f55\u786e\u5b9athis\u7684\u503c?\n  * test(): window\n  * p.test(): p\n  * new test(): \u65b0\u521b\u5efa\u7684\u5bf9\u8c61\n  * p.call(obj): obj\n--&gt;\n\n&lt;script type=\"text\/javascript\"&gt;\n  function Person(color) {\n    console.log(this)\n    this.color = color;\n    this.getColor = function () {\n      console.log(this)\n      return this.color;\n    };\n    this.setColor = function (color) {\n      console.log(this)\n      this.color = color;\n    };\n  }\n\n  Person(\"red\"); \/\/this\u662f\u8c01? window\n\n  var p = new Person(\"yello\"); \/\/this\u662f\u8c01? p\n\n  p.getColor(); \/\/this\u662f\u8c01? p\n\n  var obj = {};\n  p.setColor.call(obj, \"black\"); \/\/this\u662f\u8c01? obj\n\n  var test = p.setColor;\n  test(); \/\/this\u662f\u8c01? window\n\n  function fun1() {\n    function fun2() {\n      console.log(this);\n    }\n\n    fun2(); \/\/this\u662f\u8c01? window\n  }\n  fun1();\n&lt;\/script&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;<\/code><\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&lt;!DOCTYPE html&gt; &lt;html lang=&#8221;en&#8221;&gt; &lt;head&gt; &lt;met","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[5],"_links":{"self":[{"href":"https:\/\/blog.viter.top\/index.php\/wp-json\/wp\/v2\/posts\/414"}],"collection":[{"href":"https:\/\/blog.viter.top\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.viter.top\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.viter.top\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.viter.top\/index.php\/wp-json\/wp\/v2\/comments?post=414"}],"version-history":[{"count":0,"href":"https:\/\/blog.viter.top\/index.php\/wp-json\/wp\/v2\/posts\/414\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.viter.top\/index.php\/wp-json\/wp\/v2\/media?parent=414"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.viter.top\/index.php\/wp-json\/wp\/v2\/categories?post=414"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.viter.top\/index.php\/wp-json\/wp\/v2\/tags?post=414"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}