{"id":187339,"date":"2020-11-02T22:18:00","date_gmt":"2020-11-02T14:18:00","guid":{"rendered":"http:\/\/4563.org\/?p=187339"},"modified":"2020-11-02T22:18:00","modified_gmt":"2020-11-02T14:18:00","slug":"%e7%bb%99%e8%90%8c%e6%96%b0-html5-%e5%85%a5%e9%97%a8%e6%8c%87%e5%8d%97%ef%bc%88%e4%ba%8c%ef%bc%89","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=187339","title":{"rendered":"\u7ed9\u840c\u65b0 HTML5 \u5165\u95e8\u6307\u5357\uff08\u4e8c\uff09"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u7ed9\u840c\u65b0 HTML5 \u5165\u95e8\u6307\u5357\uff08\u4e8c\uff09               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : GrapeCityChina <\/span>  <span><i><\/i> 4<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u4e0a\u4e00\u7bc7\u6211\u4eec\u5df2\u7ecf\u4e3a\u5927\u5bb6\u4ecb\u7ecd\u4e86HTML5 \u65b0\u589e\u7684\u5185\u5bb9\u548c\u57fa\u7840\u9875\u9762\u5e03\u5c40\uff0c\u8fd9\u7bc7\u4f1a\u7ee7\u7eed\u5411\u5927\u5bb6\u4ecb\u7ecd\u5e7f\u4e49\u4e0a HTML5 \u4e2d\u53e6\u4e00\u4e2a\u7ec4\u6210\u90e8\u5206\uff1aJavaScript \u6570\u636e\u7c7b\u578b\u3002<\/p>\n<p>JavaScript \u4f5c\u4e3a\u4e00\u79cd\u5f31\u7c7b\u578b\u8bed\u8a00\uff0c\u6700\u5927\u7684\u7279\u70b9\u5c31\u662f\u52a8\u6001\u7c7b\u578b\u3002\u4e5f\u5c31\u662f\u8bf4\u4e0d\u7528\u63d0\u524d\u58f0\u660e\u53d8\u91cf\u7684\u7c7b\u578b\uff0c\u5728\u7a0b\u5e8f\u8fd0\u884c\u65f6\uff0c\u7c7b\u578b\u4f1a\u88ab\u52a8\u6001\u7684\u786e\u5b9a\uff0c\u5e76\u4e14\u5728\u6267\u884c\u8fc7\u7a0b\u4e2d\u53ef\u4ee5\u52a8\u6001\u7684\u4fee\u6539\u53d8\u91cf\u7684\u7c7b\u578b\u3002\u540c\u65f6\u4e0d\u540c\u7c7b\u578b\u53d8\u91cf\u5728\u8fd0\u7b97\u65f6\u4f1a\u81ea\u52a8\u8fdb\u884c\u9690\u5f0f\u7684\u7c7b\u578b\u8f6c\u6362\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u89c1\u7684\u9690\u5f0f\u8f6c\u6362\u793a\u4f8b\uff1a<\/p>\n<pre><code> var foo = 2020;  \/\/ typeof foo -&gt; \"number\" var foo = \"SpreadJS\"  \/\/ typeof foo -&gt; \"string\" var foo = true + 1;         \/\/ foo = 2 typeof foo -&gt; \" number\" var foo = true + false;      \/\/ foo = 1 typeof foo -&gt; \" number\" var foo = '5' - '2';          \/\/ foo = 3 typeof foo -&gt; \" number\" var foo = 20 + 20 + \"SpreadJS\" \/\/ foo = \"40SpreadJS\" typeof foo -&gt; \"string\" var foo = \"SpreadJS\" + 20 + 20 \/\/ foo = \"40SpreadJS\" typeof foo -&gt; \" string\" <\/code><\/pre>\n<p>\u4f9d\u636e\u6700\u65b0\u7684 ECMAScript \u6807\u51c6\u5c06\u6570\u636e\u7c7b\u578b\u5b9a\u4e49\u4e86 8 \u79cd\uff1a<\/p>\n<p>\u5176\u4e2d\u4e3a\u539f\u59cb\u7c7b\u578b\uff1aBoolean \u3001Null \u3001Undefined \u3001Number \u3001BigInt \u3001String \u3001Symbol \u548c\u5bf9\u8c61\u7c7b\u578b\uff1aobject<\/p>\n<p><strong>\u5173\u4e8e\u539f\u59cb\u7c7b\u578b\u9700\u8981\u77e5\u9053\u7684\u51e0\u4e2a\u77e5\u8bc6\u70b9\uff1a<\/strong><\/p>\n<ul>\n<li>\u539f\u59cb\u7c7b\u578b\u7684\u503c\u662f\u6309\u503c\u8bbf\u95ee\u7684<\/li>\n<\/ul>\n<p>\u5373\u5728\u8d4b\u503c\u548c\u4fee\u6539\u503c\u65f6\u662f\u901a\u8fc7\u503c\u4f20\u9012\u7684\u65b9\u5f0f\u6765\u5b8c\u6210\u7684\uff0c\u5bf9\u53d8\u91cf\u8d4b\u503c\u6216\u8005\u4fee\u6539\u503c\u4f1a\u5728\u5185\u5b58\u4e2d\u91cd\u65b0\u5206\u914d\u7a7a\u95f4\u3002<\/p>\n<p>\u4f8b\u5982\uff1a<\/p>\n<pre><code>var a, b, x, y; a = \" SpreadJS\"; b = \" GrapeCity\"; x = a; y = b; console.log(a, b, x, y);   \/\/ result:  SpreadJS GrapeCity SpreadJS GrapeCity <\/code><\/pre>\n<p>a \u548c x\uff0cb \u548c y \u4e4b\u95f4\u8d4b\u503c\u662f\u5b8c\u5168\u72ec\u7acb\u7684\u62f7\u8d1d\uff0c\u4e92\u4e0d\u5e72\u6d89\uff0c\u5982\u679c\u6211\u4eec\u5c06\u5176\u4e2d\u4efb\u4f55\u4e00\u4e2a\u53d8\u91cf\u7684\u503c\u91cd\u65b0\u6539\u53d8\uff0c\u5176\u4ed6\u76f8\u540c\u503c\u7684\u53d8\u91cf\u4e5f\u4e0d\u4f1a\u53d7\u5230\u4efb\u4f55\u5f71\u54cd\u3002<\/p>\n<ul>\n<li>\u4e25\u683c\u76f8\u7b49===\u548c\u975e\u4e25\u683c\u76f8\u7b49==<\/li>\n<\/ul>\n<p>\u5bf9\u4e8e\u539f\u59cb\u7c7b\u578b\uff0c==\u53ea\u8fdb\u884c\u503c\u6bd4\u8f83\uff0c\u5982\u679c\u662f\u4e0d\u540c\u7c7b\u578b\u5219\u4f1a\u5728\u8f6c\u6362\u540e\u518d\u6bd4\u8f83\uff0c===\u5219\u4f1a\u6bd4\u8f83\u6570\u636e\u7c7b\u578b\u3002<\/p>\n<p>\u4f8b\u5982\uff1a<\/p>\n<pre><code>undefined === null \/\/fasle undefined == null \/\/true true === 1 \/\/fasle true == 1 \/\/true null == 0 \/\/false <\/code><\/pre>\n<ul>\n<li>Null \u548c Undefined<\/li>\n<\/ul>\n<p>null \u548c undefined \u5728\u4f7f\u7528\u4e2d\u51e0\u4e4e\u6ca1\u6709\u533a\u522b\uff0c\u5728\u4f7f\u7528\u975e\u4e25\u683c\u76f8\u7b49\u6bd4\u8f83\u65f6\u7ed3\u679c\u4e5f\u4e3a true\uff0c\u5b83\u4eec\u7684\u533a\u522b\u5c31\u662f\u5728\u4e8e\u8fdb\u884c\u6570\u503c\u8f6c\u6362\u65f6\u5b83\u4eec\u7684\u5b57\u9762\u610f\u4e49\u4e0d\u540c\uff0cundefined \u4ee3\u8868\u672a\u5b9a\u4e49\uff0c\u8f6c\u4e3a\u6570\u503c\u4e3a NaN\uff0c\u800c null \u4e3a\u7a7a\u3001\u8f6c\u4e3a\u6570\u503c\u65f6\u4e3a 0 \u3002<\/p>\n<p>\u4f8b\u5982\uff1a<\/p>\n<p>Number(undefined) \/\/NaN Number(null) \/\/0 1 + undefined \/\/NaN 1 + null \/\/1<\/p>\n<p>\u867d\u7136\u4e24\u8005\u5dee\u522b\u4e0d\u5927\uff0c\u5e76\u4e0d\u4f1a\u4e25\u683c\u6309\u7167\u4e0a\u9762\u7684\u533a\u5206\u53bb\u4f7f\u7528\uff0c\u4f46\u5728\u5b9e\u9645\u9879\u76ee\u5e94\u7528\u4e2d\uff0c\u5bf9\u4e8e\u7a7a\u503c\u7684\u5224\u65ad\u4e24\u8005\u5219\u90fd\u9700\u8981\u8003\u8651\u3002<\/p>\n<ul>\n<li>NaN<\/li>\n<\/ul>\n<p>NaN \u5373\u00a0Not a Number\u00a0\uff0c\u8868\u793a\u4e86\u975e\u6570\u5b57\u7c7b\u578b\uff0c\u4efb\u4f55\u548c NaN \u7684\u64cd\u4f5c\u8fd4\u56de\u503c\u90fd\u662f NaN\uff0cNaN \u4e0d\u7b49\u4e8e NaN \u3002\u5176\u4e2d\u6709\u4e00\u4e2a\u5168\u5c40\u65b9\u6cd5 isNaN()\uff0c\u5b83\u7684\u4f5c\u7528\u662f\u68c0\u67e5\u4e00\u4e2a\u503c\u662f\u5426\u80fd\u88ab Number()\u00a0\u6210\u529f\u8f6c\u6362\u3002 \u5982\u679c\u80fd\u8f6c\u6362\u6210\u529f\uff0c\u5c31\u8fd4\u56de false\uff0c\u5426\u5219\u8fd4\u56de true \u3002<\/p>\n<p>\u4f8b\u5982\uff1a<\/p>\n<pre><code>NaN == NaN;  \/\/ fasle isNaN('123')   \/\/ false \u80fd\u8f6c\u6362 isNaN('abc')    \/\/ true \u4e0d\u80fd\u8f6c\u6362 <\/code><\/pre>\n<ul>\n<li>\u6d6e\u70b9\u6570\u7cbe\u5ea6\u8bef\u5dee<\/li>\n<\/ul>\n<p>\u5728 JavaScript \u4e2d\uff0c\u6574\u6570\u548c\u6d6e\u70b9\u6570\u90fd\u5c5e Number \u6570\u636e\u7c7b\u578b\uff0c\u6240\u6709\u6570\u5b57\u90fd\u662f\u4ee5 64 \u4f4d\u6d6e\u70b9\u6570\u5f62\u5f0f\u5b58\u50a8\u7684\uff0c\u4e5f\u5c31\u662f\u8bf4 JavaScript \u5e95\u5c42\u6ca1\u6709\u6574\u6570\uff0c1 \u548c 1.0 \u662f\u76f8\u540c\u7684\u3002<\/p>\n<p>\u4e0b\u9762\u4e3e\u51e0\u4e2a\u4f8b\u5b50\u6765\u8bf4\u660e\uff1a<\/p>\n<pre><code>   \/\/ \u52a0\u6cd5    0.1 + 0.2 = 0.30000000000000004    0.1 + 0.7 = 0.7999999999999999    0.2 + 0.4 = 0.6000000000000001     \/\/ \u51cf\u6cd5    0.3 - 0.2 = 0.09999999999999998    1.5 - 1.2 = 0.30000000000000004     \/\/ \u4e58\u6cd5    0.8 * 3 = 2.4000000000000004    19.9 * 100 = 1989.9999999999998     \/\/ \u9664\u6cd5    0.3 \/ 0.1 = 2.9999999999999996    0.69 \/ 10 = 0.06899999999999999     \/\/ \u6bd4\u8f83    0.1 + 0.2 === 0.3 \/\/ false    (0.3 - 0.2) === (0.2 - 0.1) \/\/ false <\/code><\/pre>\n<p>\u7c7b\u4f3c\u8fd9\u6837\u770b\u8d77\u6765\u4e0d\u4f1a\u7b97\u9519\u7684\u95ee\u9898\uff0c\u5728\u67d0\u4e9b\u7cfb\u7edf\u5c24\u5176\u662f\u6d89\u53ca\u8d22\u52a1\u7684\u7cfb\u7edf\u4e2d\u4f1a\u662f\u4e00\u4e2a\u4e25\u91cd\u7684\u95ee\u9898\uff0c\u8fd9\u91cc\u5c31\u4e0d\u5c55\u5f00\u89e3\u91ca\u53d1\u751f\u8bef\u5dee\u7684\u539f\u56e0\u4e86\uff0c\u5927\u5bb6\u53ef\u81ea\u884c\u7814\u7a76\uff0c\u6211\u4eec\u8fd9\u53ea\u5bf9\u89e3\u51b3\u65b9\u6848\u7b80\u5355\u7684\u5217\u4e00\u4e0b\uff0c1. \u53ef\u4ee5\u901a\u8fc7\u5f15\u7528\u7c7b\u4f3c Math.js \u3001decimal.js \u3001big.js \u8fd9\u6837\u7684\u7c7b\u5e93\u30022.\u5bf9\u4e8e\u5bf9\u6570\u5b57\u7cbe\u5ea6\u8981\u6c42\u4e0d\u9ad8\u7684\u7cfb\u7edf\uff0c\u53ef\u4ee5\u683c\u5f0f\u5316\u5e76\u4fdd\u7559 x \u4f4d\u5c0f\u6570\u6765\u5904\u7406\u30023. \u8ba1\u7b97\u65f6\uff0c\u5c06\u5c0f\u6570\u90e8\u5206\u548c\u6574\u6570\u90e8\u5206\u5206\u5f00\u8ba1\u7b97\u518d\u5408\u5e76\uff0c\u7b49\u3002<\/p>\n<p><strong>\u5173\u4e8e\u5f15\u7528\u7c7b\u578b\u9700\u8981\u77e5\u9053\u7684\u51e0\u4e2a\u77e5\u8bc6\u70b9\uff1a<\/strong><\/p>\n<ul>\n<li>\u5f15\u7528\u7c7b\u578b\u7684\u503c\u662f\u6309\u5f15\u7528\u8bbf\u95ee\u7684<\/li>\n<\/ul>\n<p>\u5728\u64cd\u4f5c\u5bf9\u8c61\u65f6\uff0c\u5b9e\u9645\u4e0a\u662f\u5728\u64cd\u4f5c\u5bf9\u8c61\u7684\u5f15\u7528\u800c\u4e0d\u662f\u5b9e\u9645\u7684\u5bf9\u8c61\u3002\u7ed9\u53d8\u91cf\u8d4b\u503c\u6539\u53d8\u7684\u662f\u5bf9\u8c61\u7684\u5f15\u7528\u5173\u7cfb\u3002<\/p>\n<p>\u4f8b\u5982\uff1a<\/p>\n<pre><code>var obj1 = {a:1}; var obj2 = obj1; obj1.a = 2; console.log(obj2.a) \/\/ result: 2.obj1 \u548c obj2 \u4e3a\u540c\u4e00\u5bf9\u8c61 obj1 = {a:3}; console.log(obj2.a) \/\/ result: 2.obj1 \u6307\u5411\u65b0\u5bf9\u8c61\uff0cobj2 \u4e0d\u53d8 <\/code><\/pre>\n<ul>\n<li>\u5f15\u7528\u7c7b\u578b===\u548c==\u610f\u4e49\u76f8\u540c\u90fd\u4e3a\u5f15\u7528\u7684\u6bd4\u8f83<\/li>\n<\/ul>\n<p>\u5373\u662f\u5426\u4e3a\u540c\u4e00\u5bf9\u8c61\uff0c\u5404\u7c7b\u578b\u4e4b\u95f4\u7684\u975e\u4e25\u683c\u76f8\u7b49==\u6bd4\u8f83\u7c7b\u578b\u8f6c\u6362\u53ef\u53c2\u8003\u4e0b\u8868:<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2020\/11\/20201109_5fa8e6d7096c8.png\" alt=\"\u7ed9\u840c\u65b0 HTML5 \u5165\u95e8\u6307\u5357\uff08\u4e8c\uff09\" \/><\/p>\n<h3>\u7c7b\u578b\u68c0\u6d4b<\/h3>\n<p>JavaScript \u4e2d\u7c7b\u578b\u68c0\u6d4b\u65b9\u6cd5\u6709\u5f88\u591a\uff0c\u6709\u4f8b\u5982\uff1atypeof \u3001instanceof \u3001Object.prototype.toString \u3001constructor \u3001duck type \u8fd9\u51e0\u79cd\u3002<\/p>\n<p>\u867d\u7136\u65b9\u6cd5\u5f88\u591a\uff0c\u4f46\u5224\u65ad\u601d\u8def\u5c31\u662f\u4e24\u79cd\uff1a1 \u6839\u636e\u6570\u636e\u7c7b\u578b\u5224\u65ad 2 \u6839\u636e\u6784\u9020\u51fd\u6570\u5224\u65ad\u3002<\/p>\n<ul>\n<li>\n<h4>typeof<\/h4>\n<\/li>\n<\/ul>\n<p>typeof \u53ef\u4ee5\u5224\u65ad\u6570\u636e\u7c7b\u578b\uff0c\u4f9d\u636e\u4e4b\u524d\u7684\u4ecb\u7ecd\uff0cjavascript \u53d8\u91cf\u7c7b\u578b\u5206\u4e3a\u503c\u7c7b\u578b\u548c\u5f15\u7528\u7c7b\u578b\uff0ctypeof \u5e94\u7528\u573a\u666f\u53ea\u53ef\u4ee5\u533a\u5206\u503c\u7c7b\u578b\u7684\u6570\u636e\u7c7b\u578b\uff0c\u4f8b\u5982\uff1a<\/p>\n<pre><code>typeof 42 \/\/ \"number\" typeof {} \/\/ \"object\" typeof undefined \/\/ \" undefined\" <\/code><\/pre>\n<ul>\n<li>\n<h4>instanceof<\/h4>\n<\/li>\n<\/ul>\n<p>\u548c typeof \u4e00\u6837\uff0cinstanceof \u7528\u4e8e\u5224\u65ad\u5f15\u7528\u7c7b\u578b\u7684\u6570\u636e\u7c7b\u578b\u3002<\/p>\n<p>\u4f8b\u5b50\uff1a<\/p>\n<pre><code> (function(){}) instanceof Function <\/code><\/pre>\n<p>\u5176\u4ed6\u7684\u8fd8\u6709 Object.prototype.toString \u3001constructor \u3001duck type\uff0c\u5728\u8fd9\u5c31\u4e0d\u4e00\u4e00\u4ecb\u7ecd\u3002<\/p>\n<p>\u5728\u4e86\u89e3\u4e86 JavaScript \u7684\u57fa\u7840\u6570\u636e\u7c7b\u578b\u77e5\u8bc6\u540e\uff0c\u540e\u9762\u6211\u4eec\u4f1a\u7ee7\u7eed\u4e3a\u5927\u5bb6\u501f\u7740\u4ecb\u7ecd CSS \u76f8\u5173\u7684\u5185\u5bb9\u3002<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>0<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u7ed9\u840c\u65b0 HTML5 \u5165\u95e8\u6307\u5357\uff08\u4e8c\uff09&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/187339"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=187339"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/187339\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=187339"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=187339"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=187339"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}