{"id":68,"date":"2011-11-15T09:56:27","date_gmt":"2011-11-15T01:56:27","guid":{"rendered":"https:\/\/blog.indeex.club\/?p=68"},"modified":"2020-06-20T22:41:08","modified_gmt":"2020-06-20T14:41:08","slug":"javascript%e7%9a%84%e5%87%bd%e6%95%b0-function","status":"publish","type":"post","link":"https:\/\/blog.indeex.club\/index.php\/2011\/11\/15\/javascript%e7%9a%84%e5%87%bd%e6%95%b0-function\/","title":{"rendered":"Javascript\u7684\u51fd\u6570 function"},"content":{"rendered":"<p>\u4e0a\u4e00\u6b21\u4ecb\u7ecd\u4e86Javascript\u4e2d\u7684\u503c\u7c7b\u578b\uff08\u57fa\u7840\u7c7b\u578b\uff09,\u90a3\u4e48<\/p>\n<p>\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u518d\u8ba8\u8bba\u4e00\u4e0bJavaScript\u51fd\u6570\u7684\u9b54\u529b\u5427\u3002<\/p>\n<p>JavaScript\u7684\u4ee3\u7801\u5c31\u53ea\u6709function\u4e00\u79cd\u5f62\u5f0f\uff0cfunction\u5c31\u662f\u51fd\u6570\u7684\u7c7b\u578b\u3002\u4e5f\u8bb8\u5176\u4ed6\u7f16\u7a0b\u8bed\u8a00\u8fd8\u6709procedure\u6216 method\u7b49\u4ee3\u7801\u6982\u5ff5\uff0c\u4f46\u5728JavaScript\u91cc\u53ea\u6709function\u4e00\u79cd\u5f62\u5f0f\u3002\u5f53\u6211\u4eec\u5199\u4e0b\u4e00\u4e2a\u51fd\u6570\u7684\u65f6\u5019\uff0c\u53ea\u4e0d\u8fc7\u662f\u5efa\u7acb\u4e86\u4e00\u4e2afunction\u7c7b\u578b\u7684\u5b9e\u4f53\u800c\u5df2\u3002\u8bf7\u770b\u4e0b\u9762\u7684\u7a0b\u5e8f\uff1a<\/p>\n<pre><code class=\"language-javascript line-numbers\">&lt;script&gt;\n    function myfunc() {\n        alert(\"hello\");\n    };\n    alert(typeof(myfunc));\n&lt;\/script&gt;\n<\/code><\/pre>\n<p>\u8fd9\u4e2a\u4ee3\u7801\u8fd0\u884c\u4e4b\u540e\u53ef\u4ee5\u770b\u5230typeof(myfunc)\u8fd4\u56de\u7684\u662ffunction\u3002\u4ee5\u4e0a\u7684\u51fd\u6570\u5199\u6cd5\u6211\u4eec\u79f0\u4e4b\u4e3a\u201c\u5b9a\u4e49\u5f0f\u201d\u7684\uff0c\u5982\u679c\u6211\u4eec\u5c06\u5176\u6539\u5199\u6210\u4e0b\u9762\u7684\u201c\u53d8\u91cf\u5f0f\u201d\u7684\uff0c\u5c31\u66f4\u5bb9\u6613\u7406\u89e3\u4e86\uff1a<\/p>\n<pre><code class=\"line-numbers\">&lt;script&gt;\n    var myfunc = function() {\n        alert(\"hello\");\n    };\n    alert(typeof(myfunc));\n&lt;\/script&gt;\n<\/code><\/pre>\n<p>\u8fd9\u91cc\u660e\u786e\u5b9a\u4e49\u4e86\u4e00\u4e2a\u53d8\u91cfmyfunc\uff0c\u5b83\u7684\u521d\u59cb\u503c\u88ab\u8d4b\u4e88\u4e86\u4e00\u4e2afunction\u7684\u5b9e\u4f53\u3002\u56e0\u6b64\uff0ctypeof(myfunc)\u8fd4\u56de\u7684\u4e5f\u662ffunction\u3002\u5176\u5b9e\uff0c\u8fd9\u4e24\u79cd\u51fd\u6570\u7684\u5199\u6cd5\u662f\u7b49\u4ef7\u7684\uff0c\u9664\u4e86\u4e00\u70b9\u7ec6\u5fae\u5dee\u522b\uff0c\u5176\u5185\u90e8\u5b9e\u73b0\u5b8c\u5168\u76f8\u540c\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u6211\u4eec\u5199\u7684\u8fd9\u4e9bJavaScript\u51fd\u6570\u53ea\u662f\u4e00\u4e2a\u547d\u4e86\u540d\u7684\u53d8\u91cf\u800c\u5df2\uff0c\u5176\u53d8\u91cf\u7c7b\u578b\u5373\u4e3afunction\uff0c\u53d8\u91cf\u7684\u503c\u5c31\u662f\u6211\u4eec\u7f16\u5199\u7684\u51fd\u6570\u4ee3\u7801\u4f53\u3002<\/p>\n<p>\u806a\u660e\u7684\u4f60\u6216\u8bb8\u7acb\u5373\u4f1a\u8fdb\u4e00\u6b65\u7684\u8ffd\u95ee\uff1a\u65e2\u7136\u51fd\u6570\u53ea\u662f\u53d8\u91cf\uff0c\u90a3\u4e48\u53d8\u91cf\u5c31\u53ef\u4ee5\u88ab\u968f\u610f\u8d4b\u503c\u5e76\u7528\u5230\u4efb\u610f\u5730\u65b9\u5570\uff1f<\/p>\n<p>\u6211\u4eec\u6765\u770b\u770b\u4e0b\u9762\u7684\u4ee3\u7801\uff1a<\/p>\n<pre><code class=\"line-numbers\">&lt;script&gt;\n    var myfunc = function() {\n        alert(\"hello\");\n    };\n    myfunc(); \/\/\u7b2c\u4e00\u6b21\u8c03\u7528myfunc\uff0c\u8f93\u51fahello     \n    myfunc = function() {\n        alert(\"yeah\");\n    };\n    myfunc(); \/\/\u7b2c\u4e8c\u6b21\u8c03\u7528myfunc\uff0c\u5c06\u8f93\u51fayeah\n&lt;\/script&gt;\n<\/code><\/pre>\n<p>\u8fd9\u4e2a\u7a0b\u5e8f\u8fd0\u884c\u7684\u7ed3\u679c\u544a\u8bc9\u6211\u4eec\uff1a\u7b54\u6848\u662f\u80af\u5b9a\u7684\uff01\u5728\u7b2c\u4e00\u6b21\u8c03\u7528\u51fd\u6570\u4e4b\u540e\uff0c\u51fd\u6570\u53d8\u91cf\u53c8\u88ab\u8d4b\u4e88\u4e86\u65b0\u7684\u51fd\u6570\u4ee3\u7801\u4f53\uff0c\u4f7f\u5f97\u7b2c\u4e8c\u6b21\u8c03\u7528\u8be5\u51fd\u6570\u65f6\uff0c\u51fa\u73b0\u4e86\u4e0d\u540c\u7684\u8f93\u51fa\u3002<\/p>\n<p>\u597d\u4e86\uff0c\u6211\u4eec\u53c8\u6765\u628a\u4e0a\u9762\u7684\u4ee3\u7801\u6539\u6210\u7b2c\u4e00\u79cd\u5b9a\u4e49\u5f0f\u7684\u51fd\u6570\u5f62\u5f0f\uff1a<\/p>\n<pre><code class=\"line-numbers\">&lt;script&gt;\n    function myfunc() {\n        alert(\"hello\");\n    };\n    myfunc(); \/\/\u8fd9\u91cc\u8c03\u7528myfunc\uff0c\u8f93\u51fayeah\u800c\u4e0d\u662fhello     \n    function myfunc() {\n        alert(\"yeah\");\n    };\n    myfunc(); \/\/\u8fd9\u91cc\u8c03\u7528myfunc\uff0c\u5f53\u7136\u8f93\u51fayeah\n&lt;\/script&gt;\n<\/code><\/pre>\n<p>\u6309\u7406\u8bf4\uff0c\u4e24\u4e2a\u7b7e\u540d\u5b8c\u5168\u76f8\u540c\u7684\u51fd\u6570\uff0c\u5728\u5176\u4ed6\u7f16\u7a0b\u8bed\u8a00\u4e2d\u5e94\u8be5\u662f\u975e\u6cd5\u7684\u3002\u4f46\u5728JavaScript\u4e2d\uff0c\u8fd9\u6ca1\u9519\u3002\u4e0d\u8fc7\uff0c\u7a0b\u5e8f\u8fd0\u884c\u4e4b\u540e\u5374\u53d1\u73b0\u4e00\u4e2a\u5947\u602a\u7684\u73b0\u8c61\uff1a\u4e24\u6b21\u8c03\u7528\u90fd\u53ea\u662f\u6700\u540e\u90a3\u4e2a\u51fd\u6570\u91cc\u8f93\u51fa\u7684\u503c\uff01\u663e\u7136\u7b2c\u4e00\u4e2a\u51fd\u6570\u6ca1\u6709\u8d77\u5230\u4efb\u4f55\u4f5c\u7528\u3002\u8fd9\u53c8\u662f\u4e3a\u4ec0\u4e48\u5462\uff1f<\/p>\n<p>\u539f\u6765\uff0cJavaScript\u6267\u884c\u5f15\u64ce\u5e76\u975e\u4e00\u884c\u4e00\u884c\u5730\u5206\u6790\u548c\u6267\u884c\u7a0b\u5e8f\uff0c\u800c\u662f\u4e00\u6bb5\u4e00\u6bb5\u5730\u5206\u6790\u6267\u884c\u7684\u3002\u800c\u4e14\uff0c\u5728\u540c\u4e00\u6bb5\u7a0b\u5e8f\u7684\u5206\u6790\u6267\u884c\u4e2d\uff0c\u5b9a\u4e49\u5f0f\u7684\u51fd\u6570\u8bed\u53e5\u4f1a\u88ab\u63d0\u53d6\u51fa\u6765\u4f18\u5148\u6267\u884c\u3002\u51fd\u6570\u5b9a\u4e49\u6267\u884c\u5b8c\u4e4b\u540e\uff0c\u624d\u4f1a\u6309\u987a\u5e8f\u6267\u884c\u5176\u4ed6\u8bed\u53e5\u4ee3\u7801\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u5728\u7b2c\u4e00\u6b21\u8c03\u7528myfunc\u4e4b\u524d\uff0c\u7b2c\u4e00\u4e2a\u51fd\u6570\u8bed\u53e5\u5b9a\u4e49\u7684\u4ee3\u7801\u903b\u8f91\uff0c\u5df2\u88ab\u7b2c\u4e8c\u4e2a\u51fd\u6570\u5b9a\u4e49\u8bed\u53e5\u8986\u76d6\u4e86\u3002\u6240\u4ee5\uff0c\u4e24\u6b21\u90fd\u8c03\u7528\u90fd\u662f\u6267\u884c\u6700\u540e\u4e00\u4e2a\u51fd\u6570\u903b\u8f91\u4e86\u3002<\/p>\n<p>\u5982\u679c\u628a\u8fd9\u4e2aJavaScript\u4ee3\u7801\u5206\u6210\u4e24\u6bb5\uff0c\u4f8b\u5982\u5c06\u5b83\u4eec\u5199\u5728\u4e00\u4e2ahtml\u4e2d\uff0c\u5e76\u7528<script\/>\u6807\u7b7e\u5c06\u5176\u5206\u6210\u8fd9\u6837\u7684\u4e24\u5757\uff1a<\/p>\n<pre><code class=\"line-numbers\">&lt;script&gt;\n    function myfunc() {\n        alert(\"hello\");\n    };\n    myfunc(); \/\/\u8fd9\u91cc\u8c03\u7528myfunc\uff0c\u8f93\u51fahello\n&lt;\/script&gt;\n&lt;script&gt;\n    function myfunc() {\n        alert(\"yeah\");\n    };\n    myfunc(); \/\/\u8fd9\u91cc\u8c03\u7528myfunc\uff0c\u8f93\u51fayeah\n&lt;\/script&gt;\n<\/code><\/pre>\n<p>\u8fd9\u65f6\uff0c\u8f93\u51fa\u624d\u662f\u5404\u81ea\u6309\u987a\u5e8f\u6765\u7684\uff0c\u4e5f\u8bc1\u660e\u4e86JavaScript\u7684\u786e\u662f\u4e00\u6bb5\u6bb5\u5730\u6267\u884c\u7684\u3002<\/p>\n<p>\u4e00\u6bb5\u4ee3\u7801\u4e2d\u7684\u5b9a\u4e49\u5f0f\u51fd\u6570\u8bed\u53e5\u4f1a\u4f18\u5148\u6267\u884c\uff0c\u8fd9\u4f3c\u4e4e\u6709\u70b9\u8c61\u9759\u6001\u8bed\u8a00\u7684\u7f16\u8bd1\u6982\u5ff5\u3002\u6240\u4ee5\uff0c\u8fd9\u4e00\u7279\u5f81\u4e5f\u88ab\u6709\u4e9b\u4eba\u79f0\u4e3a\uff1aJavaScript\u7684\u201c\u9884\u7f16\u8bd1\u201d\u3002<\/p>\n<p>\u5927\u591a\u6570\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u4e5f\u6ca1\u6709\u5fc5\u8981\u53bb\u7ea0\u7f20\u8fd9\u4e9b\u7ec6\u8282\u95ee\u9898\u3002\u53ea\u8981\u4f60\u8bb0\u4f4f\u4e00\u70b9\uff1aJavaScript\u91cc\u7684\u4ee3\u7801\u4e5f\u662f\u4e00\u79cd\u6570\u636e\uff0c\u540c\u6837\u53ef\u4ee5\u88ab\u4efb\u610f\u8d4b\u503c\u548c\u4fee\u6539\u7684\uff0c\u800c\u5b83\u7684\u503c\u5c31\u662f\u4ee3\u7801\u7684\u903b\u8f91\u3002\u53ea\u662f\uff0c\u4e0e\u4e00\u822c\u6570\u636e\u4e0d\u540c\u7684\u662f\uff0c\u51fd\u6570\u662f\u53ef\u4ee5\u88ab\u8c03\u7528\u6267\u884c\u7684\u3002<\/p>\n<p>\u4e0d\u8fc7\uff0c\u5982\u679cJavaScript\u51fd\u6570\u4ec5\u4ec5\u53ea\u6709\u8fd9\u70b9\u9053\u884c\u7684\u8bdd\uff0c\u8fd9\u4e0eC++\u7684\u51fd\u6570\u6307\u9488\uff0cDELPHI\u7684\u65b9\u6cd5\u6307\u9488\uff0cC#\u7684\u59d4\u6258\u76f8\u6bd4\uff0c\u53c8\u6709\u5565\u7a00\u5947\u7684\uff01\u7136\u800c\uff0cJavaScript\u51fd\u6570\u7684\u795e\u5947\u4e4b\u5904\u8fd8\u4f53\u73b0\u5728\u53e6\u5916\u4e24\u4e2a\u65b9\u9762\uff1a\u4e00\u662f\u51fd\u6570function\u7c7b\u578b\u672c\u8eab\u4e5f\u5177\u6709\u5bf9\u8c61\u5316\u7684\u80fd\u529b\uff0c\u4e8c\u662f\u51fd\u6570function\u4e0e\u5bf9\u8c61 object\u8d85\u7136\u7684\u7ed3\u5408\u80fd\u529b\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e0a\u4e00\u6b21\u4ecb\u7ecd\u4e86Javascript\u4e2d\u7684\u503c\u7c7b\u578b\uff08\u57fa\u7840\u7c7b\u578b\uff09,\u90a3\u4e48 \u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u518d\u8ba8\u8bba\u4e00\u4e0bJavaScri<a href=\"https:\/\/blog.indeex.club\/index.php\/2011\/11\/15\/javascript%e7%9a%84%e5%87%bd%e6%95%b0-function\/\" class=\"read-more\">Read More<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[4],"_links":{"self":[{"href":"https:\/\/blog.indeex.club\/index.php\/wp-json\/wp\/v2\/posts\/68"}],"collection":[{"href":"https:\/\/blog.indeex.club\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.indeex.club\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.indeex.club\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.indeex.club\/index.php\/wp-json\/wp\/v2\/comments?post=68"}],"version-history":[{"count":1,"href":"https:\/\/blog.indeex.club\/index.php\/wp-json\/wp\/v2\/posts\/68\/revisions"}],"predecessor-version":[{"id":69,"href":"https:\/\/blog.indeex.club\/index.php\/wp-json\/wp\/v2\/posts\/68\/revisions\/69"}],"wp:attachment":[{"href":"https:\/\/blog.indeex.club\/index.php\/wp-json\/wp\/v2\/media?parent=68"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.indeex.club\/index.php\/wp-json\/wp\/v2\/categories?post=68"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.indeex.club\/index.php\/wp-json\/wp\/v2\/tags?post=68"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}