{"id":3828,"date":"2017-08-18T17:15:15","date_gmt":"2017-08-18T08:15:15","guid":{"rendered":"https:\/\/www.sria.co.jp\/blog\/?p=3828"},"modified":"2017-08-18T17:12:00","modified_gmt":"2017-08-18T08:12:00","slug":"javascript-function","status":"publish","type":"post","link":"https:\/\/www.sria.co.jp\/blog\/2017\/08\/javascript-function\/","title":{"rendered":"JavaScript \u95a2\u6570\uff08function\uff09\u306e\u57fa\u790e\u3092\u5b66\u3076"},"content":{"rendered":"<p>\u5b9f\u52d9\u7d4c\u9a131\u30f6\u6708\u3001\u30a8\u30c7\u30a3\u30bf\u30fc\u306e\u82e5\u6801\u3067\u3059\u3002<br \/>\nJavaScript\u306e\u95a2\u6570\uff08function\uff09\u306b\u3064\u3044\u3066\u3001\u5b9f\u52d9\u306e\u4e2d\u3067\u5b66\u3093\u3060\u3053\u3068\u3092\u66f8\u3044\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<h2>\u95a2\u6570\u3068\u306f\uff1f<\/h2>\n<p>\u95a2\u6570\u306f\u3001\u4efb\u610f\u306e\u51e6\u7406\u3092\u5b9f\u884c\u3059\u308b\u30b3\u30fc\u30c9\u3092\u307e\u3068\u3081\u3001\u540d\u524d\u3092\u3064\u3051\u305f\u3082\u306e\u3002<br \/>\n\u95a2\u6570\u3092\u4f7f\u3046\u3053\u3068\u3067\u3001<\/p>\n<ul>\n<li>\u8907\u6570\u306e\u51e6\u7406\u3092\u307e\u3068\u3081\u3089\u308c\u308b<\/li>\n<li>\u540c\u3058\u51e6\u7406\u3067\u3042\u308c\u3070\u3001\u95a2\u6570\u3092\u518d\u5229\u7528\u3067\u304d\u308b<\/li>\n<li>\u540c\u3058\u30b3\u30fc\u30c9\u3092\u4f55\u5ea6\u3082\u66f8\u304b\u306a\u304f\u3066\u3044\u3044\u306e\u3067\u3001\u7d50\u679c\u3001\u30b3\u30fc\u30c9\u3082\u3059\u3063\u304d\u308a\u3059\u308b<\/li>\n<\/ul>\n<p>\u3068\u3044\u3046\u30e1\u30ea\u30c3\u30c8\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<h2>\u95a2\u6570\u306e\u5ba3\u8a00\u65b9\u6cd5\u306b\u3064\u3044\u3066<\/h2>\n<p>\u95a2\u6570\u306f\u3001\u81ea\u5206\u3067\u540d\u524d\u3092\u3064\u3051\u3089\u308c\u307e\u3059\u3002\u540d\u524d\u3092\u3064\u3051\u308b\u6642\u306f\u3001\u30ed\u30fc\u30ef\u30fc\u30ad\u30e3\u30e1\u30eb\u30b1\u30fc\u30b9\u3067\u66f8\u304f\u306e\u304c\u4e00\u822c\u7684\u3067\u3059\u3002<br \/>\nJavaScript\u3067\u540d\u524d\u3092\u3064\u3051\u308b\u6642\u306e\u30eb\u30fc\u30eb\u3092\u77e5\u308a\u305f\u3044\u65b9\u306f\u3001\u4ee5\u524d\u306e\u300c<a href=\"https:\/\/www.sria.co.jp\/blog\/2017\/06\/camelcase\/\" target=\"_blank\" rel=\"noopener\">JavaScript\u7de8\u547d\u540d\u898f\u5247<\/a>\u300d\u3092\u8aad\u3093\u3067\u304f\u3060\u3055\u3044\uff01<\/p>\n<p>\u95a2\u6570\u306f\u3001\u6b21\u306e\u3088\u3046\u306b\u5ba3\u8a00\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"lang:js decode:true \">function \u95a2\u6570\u540d(\u5f15\u6570){\r\n\r\n\/\/\u5b9f\u884c\u3057\u305f\u3044\u30b3\u30fc\u30c9\u3092\u66f8\u304f;\r\n\r\n}\r\n<\/pre>\n<p>\u3053\u3046\u66f8\u3044\u3066\u3082\u300c\u95a2\u6570\u3092\u4f5c\u308a\u307e\u3057\u305f\uff01\u300d\u3068\u5ba3\u8a00\u3059\u308b\u3060\u3051\u306a\u306e\u3067\u3001\u305d\u306e\u5834\u3067\u5b9f\u884c\u306f\u3055\u308c\u307e\u305b\u3093\u3002<br \/>\n\u3053\u306e\u95a2\u6570\u3092\u4f7f\u3063\u3066\u51e6\u7406\u3092\u3057\u305f\u3044\u6642\u306b\u306f\u3001<\/p>\n<pre class=\"lang:js decode:true \">\u95a2\u6570\u540d(\u5f15\u6570);\r\n<\/pre>\n<p>\u3068\u547c\u3073\u51fa\u3057\u3066\u5b9f\u884c\u3057\u307e\u3059\u3002<\/p>\n<h2>\u5f15\u6570\u3068\u306f\uff1f<\/h2>\n<p>\u5f15\u6570\u306f\u3001\u95a2\u6570\u306e\u547c\u3073\u51fa\u3057\u5143\u304c\u4e0e\u3048\u308b\u5024\u306e\u3053\u3068\u3002<br \/>\n\u4ee5\u4e0b\u306f\u3001a\u3068b\u3068\u3044\u30462\u3064\u306e\u5f15\u6570\u3092\u4e0e\u3048\u3066\u3001\u30b3\u30f3\u30bd\u30fc\u30eb\u306ba\u3068b\u306e\u548c\u3092\u51fa\u529b\u3059\u308b\u51e6\u7406\u3092\u5ba3\u8a00\u3057\u305f\u30b3\u30fc\u30c9\u3067\u3059\u3002<\/p>\n<pre class=\"lang:js decode:true\">function sum(a,b){\r\n  console.log(a+b);\r\n}\r\n\r\nsum(5,7); \/\/ \u30b3\u30f3\u30bd\u30fc\u30eb\u306b12\u304c\u51fa\u529b\r\n<\/pre>\n<p>\u95a2\u6570\u3092\u547c\u3073\u51fa\u3057\u3001\u5f15\u6570\u306ba=5,b=7\u3092\u4e0e\u3048\u308b\u3068\u30015\u30687\u306e\u548c\uff1d12\u304c\u30b3\u30f3\u30bd\u30fc\u30eb\u306b\u51fa\u529b\u3055\u308c\u307e\u3059\u3002<\/p>\n<p>\u5f15\u6570\u306f\u7701\u7565\u3082\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"lang:js decode:true \">function message(){\r\n  console.log('Welcome to our site!')\r\n}\r\n\r\nmessage(); \/\/\u3000\u30b3\u30f3\u30bd\u30fc\u30eb\u306b\u3000Welcome to our site!\u3068\u51fa\u529b\r\n<\/pre>\n<h2>return\u6587\u306e\u4f7f\u3044\u65b9<\/h2>\n<p>\u95a2\u6570\u306e\u4e2d\u3067return\u6587\u3092\u4f7f\u3046\u3053\u3068\u3067\u3001\u305d\u306e\u95a2\u6570\u306b\u3088\u3063\u3066\u8fd4\u3055\u308c\u308b\u5024\uff08=\u623b\u308a\u5024\uff09\u3082\u6307\u5b9a\u3067\u304d\u307e\u3059\u3002<br \/>\n\u4e0b\u306e\u30b3\u30fc\u30c9\u4f8b\u3060\u3068\u3001return\u306e\u5f8c\u308d\u306b\u3042\u308b\u300c&#8217;\u3053\u3093\u306b\u3061\u306f\u3001&#8217; + name + &#8216;\u3055\u3093\u3002&#8217;\u300d\u304c\u623b\u308a\u5024\u3067\u3059\u3002<br \/>\nname\u306f\u5f15\u6570\u306a\u306e\u3067\u3001\u6307\u5b9a\u3055\u308c\u305f\u5f15\u6570\u306e\u6587\u5b57\u5217\u304c\u7d50\u5408\u3055\u308c\u3066\u3001\u300c\u3053\u3093\u306b\u3061\u306f\u3001\u25cf\u25cf\u3055\u3093\u3002\u300d\u3068\u8868\u793a\u3055\u308c\u307e\u3059\u3002<br \/>\n\u623b\u308a\u5024\u306e\u6307\u5b9a\u306f\u3001return\u6587\u3067\u3057\u304b\u3067\u304d\u307e\u305b\u3093\u3002<\/p>\n<pre class=\"lang:js decode:true\">function hello(name){\r\n  return '\u3053\u3093\u306b\u3061\u306f\u3001' + name + '\u3055\u3093\u3002';\r\n}\r\n\r\nconsole.log(hello('\u685c\u4e95')); \/\/ \u30b3\u30f3\u30bd\u30fc\u30eb\u306b\u306f\u300c\u3053\u3093\u306b\u3061\u306f\u3001\u685c\u4e95\u3055\u3093\u3002\u300d\u304c\u51fa\u529b\r\n<\/pre>\n<p>\u95a2\u6570\u3092\u5909\u6570\u306b\u5165\u308c\u3066\u3001\u305d\u306e\u5909\u6570\u3092\u547c\u3073\u51fa\u3057\u3066\u3082\u623b\u308a\u5024\u3092\u53d6\u5f97\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"lang:js decode:true\">function hello(name){\r\n  return '\u3053\u3093\u306b\u3061\u306f\u3001' + name + '\u3055\u3093\u3002';\r\n}\r\n        \r\nvar message = hello('\u6749\u7530');\r\nconsole.log(message); \/\/ \u30b3\u30f3\u30bd\u30fc\u30eb\u306b\u306f\u300c\u3053\u3093\u306b\u3061\u306f\u3001\u6749\u7530\u3055\u3093\u3002\u300d\u304c\u51fa\u529b\r\n<\/pre>\n<h2>\u7121\u540d\u95a2\u6570\u3068\u5373\u6642\u95a2\u6570<\/h2>\n<p>\u305d\u306e\u4ed6\u3001\u95a2\u6570\u306b\u3082\u30d1\u30bf\u30fc\u30f3\u304c\u3042\u308b\u306e\u3067\u3055\u3089\u3063\u3068\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n<h3>\u7121\u540d\u95a2\u6570(\u533f\u540d\u95a2\u6570)\u3068\u306f\uff1f<\/h3>\n<p>\u7121\u540d\u95a2\u6570\u306f\u3001\u95a2\u6570\u540d\u304c\u7701\u7565\u3055\u308c\u305f\u95a2\u6570\u306e\u3053\u3068\u3002<br \/>\n\u5909\u6570\u306e\u4e2d\u306b\u95a2\u6570\u306e\u51e6\u7406\u3092\u5b9a\u7fa9\u3059\u308b\u3068\u3001\u95a2\u6570\u540d\u3092\u7701\u7565\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"lang:js decode:true \">var hello = function(name){\r\n  console.log('\u3053\u3093\u306b\u3061\u306f\u3001' + name + '\u3055\u3093\u3002');\r\n};\r\n\r\nhello('\u685c\u4e95'); \u3000\/\/ \u30b3\u30f3\u30bd\u30fc\u30eb\u306b\u306f\u300c\u3053\u3093\u306b\u3061\u306f\u3001\u685c\u4e95\u3055\u3093\u3002\u300d\u304c\u51fa\u529b\r\n<\/pre>\n<p>\u5909\u6570hello()\u3092\u4f7f\u3048\u3070\u95a2\u6570\u3092\u547c\u3073\u51fa\u305b\u308b\u306e\u3067\u3001\u95a2\u6570\u540d\u306f\u7701\u7565\u3067\u304d\u307e\u3059\u3002\u3053\u308c\u304c\u7121\u540d\u95a2\u6570\u3067\u3059\u3002<\/p>\n<p>\u95a2\u6570\u3092\u4f7f\u3046\u30e1\u30ea\u30c3\u30c8\u3068\u3057\u3066\u300c\u540c\u3058\u51e6\u7406\u3067\u3042\u308c\u3070\u3001\u95a2\u6570\u3092\u518d\u5229\u7528\u3067\u304d\u308b\u300d\u3068\u3044\u3046\u70b9\u3092\u6700\u521d\u306b\u6319\u3052\u307e\u3057\u305f\u304c\u3001<br \/>\n\u518d\u5229\u7528\u3057\u306a\u3044\u95a2\u6570\u3067\u3042\u308c\u3070\u3001\u305d\u306e\u5834\u3067\u5ba3\u8a00\u3057\u3066\u5b9f\u884c\u3055\u308c\u308c\u3070\u3088\u3044\u3001\u3068\u3082\u8a00\u3048\u307e\u3059\u3002<br \/>\n\u305d\u306e\u70b9\u3067\u306f\u3001\u7121\u540d\u95a2\u6570\u306f\u518d\u5229\u7528\u3057\u306a\u3044\u95a2\u6570\u5411\u304d\u3060\u3068\u3082\u8a00\u3048\u307e\u3059\u3002<\/p>\n<h3>\u5373\u6642\u95a2\u6570\u3068\u306f\uff1f<\/h3>\n<p>\u5373\u6642\u95a2\u6570\u306f\u3001\u95a2\u6570\u306e\u5ba3\u8a00\u3068\u5b9f\u884c\u304c\u540c\u6642\u306b\u884c\u308f\u308c\u308b\u95a2\u6570\u306e\u3053\u3068\u3002<br \/>\n\u95a2\u6570\u540d\u3092\u7701\u7565\u3067\u304d\u308b\u306e\u3067\u3001\u7121\u540d\u95a2\u6570\u306e\u4ef2\u9593\u3068\u3082\u8a00\u3048\u307e\u3059\u3002<\/p>\n<p>\u7121\u540d\u95a2\u6570\u306e\u66f8\u304d\u65b9\u304b\u3089\u3001\u3055\u3089\u306b\u5909\u6570\u540d\u3092\u7701\u7565\u3057\u3066\u3044\u304f\u3068\u5373\u6642\u95a2\u6570\u306e\u5f62\u5f0f\u306b\u306a\u308a\u307e\u3059\u3002<br \/>\n\u3067\u3059\u304c\u3001\u5358\u306b\u5909\u6570\u5b9a\u7fa9\u306evar hello\u3084\u3001\u5909\u6570\u540dhello\u3092\u7701\u7565\u3057\u305f\u3060\u3051\u3067\u306f\u30a8\u30e9\u30fc\u304c\u51fa\u307e\u3059\u3002<\/p>\n<pre class=\"lang:js decode:true\">function(name){\r\n  console.log('\u3053\u3093\u306b\u3061\u306f\u3001' + name + '\u3055\u3093\u3002');\r\n}('\u685c\u4e95');\r\n\r\n\/\/\u7d50\u679c\r\nUncaught SyntaxError: Unexpected token (\r\n<\/pre>\n<p>\u305d\u306e\u30a8\u30e9\u30fc\u3092\u56de\u907f\u3059\u308b\u305f\u3081\u306b\u3001\u95a2\u6570\u5ba3\u8a00\u90e8\u5206\u5168\u4f53\u3092()\u3067\u56f2\u307f\u307e\u3059\u3002<\/p>\n<pre class=\"lang:js decode:true\">(function(name){\r\n  console.log('\u3053\u3093\u306b\u3061\u306f\u3001' + name + '\u3055\u3093\u3002');\r\n})('\u685c\u4e95'); \r\n<\/pre>\n<p>\u5ba3\u8a00\u3068\u540c\u6642\u306b\u5b9f\u884c\u3055\u308c\u308b\u3001\u5373\u6642\u95a2\u6570\u304c\u3067\u304d\u307e\u3057\u305f\u3002<\/p>\n<p>\u3053\u306e\u5834\u5408\u306e()\u306f\u3001<strong>\u30b0\u30eb\u30fc\u30d7\u5316\u6f14\u7b97\u5b50<\/strong>\u3068\u3044\u3046\u540d\u524d\u3067\u3001()\u3067\u56f2\u3046\u3053\u3068\u3067\u95a2\u6570\u306e\u5ba3\u8a00\u3068\u51e6\u7406\u304c\u30b0\u30eb\u30fc\u30d7\u5316\u3055\u308c\u3066\u3001\u30a8\u30e9\u30fc\u306a\u304f\u5b9f\u884c\u3055\u308c\u307e\u3059\u3002<br \/>\n\u5148\u306b\u6319\u3052\u305f\u65b9\u6cd5\u306b\u6bd4\u3079\u308b\u3068\u3001\u95a2\u6570\u540d\u3092\u5b9a\u7fa9\u3057\u306a\u3044\u306e\u3067\u30b3\u30fc\u30c9\u304c\u7169\u96d1\u306b\u306a\u3089\u306a\u3044\u3001\u3068\u3044\u3046\u30e1\u30ea\u30c3\u30c8\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>\u4ee5\u4e0a\u3067\u3001JavaScript \u95a2\u6570\uff08function\uff09\u306e\u57fa\u790e\u3092\u5b66\u3076\u3001\u306e\u56de\u3092\u7d42\u308f\u308a\u307e\u3059\u3002<\/p>\n<p>\u304a\u4e16\u8a71\u306b\u306a\u3063\u305fURL<br \/>\n<a href=\"http:\/\/cou929.nu\/data\/google_javascript_style_guide\/index.html?highlight=%E9%96%A2%E6%95%B0#id12\" target=\"_blank\" rel=\"noopener\">Google JavaScript Style Guide \u548c\u8a33<\/a><br \/>\n<a href=\"https:\/\/developer.mozilla.org\/ja\/docs\/Web\/JavaScript\/Guide\/Functions\" target=\"_blank\" rel=\"noopener\">\u95a2\u6570-JavaScript(MDN)<\/a><br \/>\n<a href=\"https:\/\/www.w3schools.com\/js\/js_function_definition.asp\" target=\"_blank\" rel=\"noopener\">JavaScript Function Definitions(w3school.com)<\/a><br \/>\n<a href=\"https:\/\/developer.mozilla.org\/ja\/docs\/Web\/JavaScript\/Reference\/Operators\/Grouping\" target=\"_blank\" rel=\"noopener\">\u30b0\u30eb\u30fc\u30d7\u5316\u6f14\u7b97\u5b50-JavaScript(MDN)<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b9f\u52d9\u7d4c\u9a131\u30f6\u6708\u3001\u30a8\u30c7\u30a3\u30bf\u30fc\u306e\u82e5\u6801\u3067\u3059\u3002 JavaScript\u306e\u95a2\u6570\uff08function\uff09\u306b\u3064\u3044\u3066\u3001\u5b9f\u52d9\u306e\u4e2d\u3067\u5b66\u3093\u3060\u3053\u3068\u3092\u66f8\u3044\u3066\u3044\u304d\u307e\u3059\u3002 \u95a2\u6570\u3068\u306f\uff1f \u95a2\u6570\u306f\u3001\u4efb\u610f\u306e\u51e6\u7406\u3092\u5b9f\u884c\u3059\u308b\u30b3\u30fc\u30c9\u3092\u307e\u3068\u3081\u3001\u540d\u524d\u3092\u3064\u3051\u305f\u3082\u306e\u3002 \u95a2\u6570\u3092\u4f7f&#8230;<\/p>\n","protected":false},"author":5,"featured_media":3042,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[14,8],"tags":[149,49,133,152,151,153,150],"_links":{"self":[{"href":"https:\/\/www.sria.co.jp\/blog\/wp-json\/wp\/v2\/posts\/3828"}],"collection":[{"href":"https:\/\/www.sria.co.jp\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sria.co.jp\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sria.co.jp\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sria.co.jp\/blog\/wp-json\/wp\/v2\/comments?post=3828"}],"version-history":[{"count":56,"href":"https:\/\/www.sria.co.jp\/blog\/wp-json\/wp\/v2\/posts\/3828\/revisions"}],"predecessor-version":[{"id":3905,"href":"https:\/\/www.sria.co.jp\/blog\/wp-json\/wp\/v2\/posts\/3828\/revisions\/3905"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.sria.co.jp\/blog\/wp-json\/wp\/v2\/media\/3042"}],"wp:attachment":[{"href":"https:\/\/www.sria.co.jp\/blog\/wp-json\/wp\/v2\/media?parent=3828"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sria.co.jp\/blog\/wp-json\/wp\/v2\/categories?post=3828"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sria.co.jp\/blog\/wp-json\/wp\/v2\/tags?post=3828"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}