{"id":4913,"date":"2023-10-01T11:35:36","date_gmt":"2023-10-01T02:35:36","guid":{"rendered":"http:\/\/attacktube.com\/?p=4913"},"modified":"2023-10-01T11:48:01","modified_gmt":"2023-10-01T02:48:01","slug":"%e3%80%90javascript%e3%80%91eventuality%e9%96%a2%e6%95%b0","status":"publish","type":"post","link":"https:\/\/attacktube.com\/?p=4913","title":{"rendered":"\u3010JavaScript\u3011eventuality\u95a2\u6570"},"content":{"rendered":"\n<p>JavaScript the good parts P64\uff5e65\u306b\u8f09\u3063\u3066\u3044\u308beventuality\u95a2\u6570\u306b\u3064\u3044\u3066\u66f8\u3044\u3066\u3044\u304f\u3002<\/p>\n\n\n\n<!--more-->\n\n\n\n<br>\n<script async=\"\" src=\"https:\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js?client=ca-pub-3461056110605997\" crossorigin=\"anonymous\"><\/script>\n<ins class=\"adsbygoogle\" style=\"display:block; text-align:center;\" data-ad-layout=\"in-article\" data-ad-format=\"fluid\" data-ad-client=\"ca-pub-3461056110605997\" data-ad-slot=\"3137443461\"><\/ins>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script>\n<br>\n\n\n\n<pre><code>\nvar eventuality = function(that) {\n  var registry = {};\n  that.fire = function(event) {\n    \/\/ Fire an event on an object. The event can be either\n    \/\/ a string containing the name of the event or an object\n    \/\/ containing a type property containing the name of event.\n    \/\/ Handlers registered by the 'on' method that match the\n    \/\/ event name will be invoked.\n    var array;\n    var func;\n    var handler;\n    var i;\n    var type = typeof event === 'string' ? event : event.type;\n    \/\/ If an array of handlers exist for this event, then\n    \/\/ loop throught it and execute the handlers in order.\n    if (registry.hasOwnProperty(type)) {\n      array = registry[type];\n      for (i = 0; i < array.length; i += 1) {\n        handler = array[i];\n        \/\/ A handler record contains a method and an optional\n        \/\/ array of parameters. If the method is a name, look\n        \/\/ up the function.\n        func = handler.method;\n        if (typeof func === 'string') {\n          func = this[func];\n        }\n        \/\/ Invoke a handler. If the record contained parameters,\n        \/\/ then pass them. Otherwise, pass the event object.\n\n        func.apply(this, handler.parameters || [event]);\n      }\n    }\n    return this;\n  };\n  that.on = function(type, method, parameters) {\n    \/\/ Register an event. Make a handler record. Put it \n    \/\/ in a handler array, making one if it doesn't yet \n    \/\/ exist for this type.\n    var handler = {\n      method: method,\n      parameters: parameters\n    };\n    if (registry.hasOwnProperty(type)) {\n      registry[type].push(handler);\n    } else {\n      registery[type] = [handler];\n    }\n    return this;\n  };\n  return that;\n};\n<\/code><\/pre>\n\n\n\n<p>--JavaScript the good parts P65\u304b\u3089\u5f15\u7528 \u3053\u3053\u304b\u3089--<br>\u4efb\u610f\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u5f15\u6570\u306beventuality\u95a2\u6570\u3092\u547c\u3073\u51fa\u3059\u3053\u3068\u3067\u3001\u305d\u308c\u3089\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306b\u30a4\u30d9\u30f3\u30c8\u30cf\u30f3\u30c9\u30ea\u30f3\u30b0\u3092\u884c\u3046\u30e1\u30bd\u30c3\u30c9\u3092\u8ffd\u52a0\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u3002\u3053\u306e\u95a2\u6570\u3092\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u5185\u3067that\u3092\u8fd4\u3059\u524d\u306b\u547c\u3073\u51fa\u3057\u3066\u3057\u307e\u3046\u3053\u3068\u3082\u3067\u304d\u308b\u3002<br>--JavaScript the good parts P65\u304b\u3089\u5f15\u7528 \u3053\u3053\u307e\u3067--<br><br>\u79c1\u304c\u7406\u89e3\u3067\u304d\u306a\u304b\u3063\u305f\u306e\u306f\u3001\u300c\u3053\u306e\u95a2\u6570\u3092\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u5185\u3067that\u3092\u8fd4\u3059\u524d\u306b\u547c\u3073\u51fa\u3057\u3066\u3057\u307e\u3046\u3053\u3068\u3082\u3067\u304d\u308b\u3002\u300d\u3068\u306f\u4f55\u3092\u8a00\u3063\u3066\u3044\u308b\u306e\u304b\uff1f<br><br>\u300ceventuality\u95a2\u6570\u306b\u5f15\u6570\u3092\u6e21\u3057\u3066\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u95a2\u6570\u306e\u4e2d\u3067\u547c\u3073\u51fa\u3059\u3067\u3042\u308b\u3002\u3053\u308c\u306b\u3088\u308a\u3001\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u95a2\u6570\u304c\u65b0\u3057\u3044\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u4f5c\u6210\u3057\u3001\u305d\u308c\u306b\u5bfe\u3057\u3066\u30a4\u30d9\u30f3\u30c8\u95a2\u9023\u306e\u6a5f\u80fd\u3092\u8ffd\u52a0\u3057\u305f\u5f8c\u3067\u3001\u305d\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u304c\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u95a2\u6570\u304b\u3089\u8fd4\u3055\u308c\u308b\u3002\u300d\u3068\u3044\u3046\u3053\u3068\u3092\u8a00\u3044\u305f\u3044\u307f\u305f\u3044\u3060\u306a\u3002<\/p>\n\n\n\n<p>\u4f7f\u7528\u4f8b\u306f\u6b21\u306e\u3088\u3046\u306b\u306a\u308b\u3068\u601d\u308f\u308c\u308b\u3002<\/p>\n\n\n\n<pre><code>\nfunction MyConstructor() {\n  \/\/ \u65b0\u3057\u3044\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u4f5c\u6210\n  var newObj = {};\n\n  \/\/ newObj\u306b\u30a4\u30d9\u30f3\u30c8\u95a2\u9023\u306e\u6a5f\u80fd\u3092\u8ffd\u52a0\n  eventuality(newObj);\n\n  \/\/ \u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u8fd4\u3059\n  return newObj;\n}\n\n\/\/ eventuality\u3092\u4f7f\u3063\u3066\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u4f5c\u6210\u3057\u3001\u305d\u308c\u306b\u5bfe\u3057\u3066\u30a4\u30d9\u30f3\u30c8\u95a2\u9023\u306e\u6a5f\u80fd\u3092\u8ffd\u52a0\nvar instance = new MyConstructor();\n\n\/\/ \u30a4\u30d9\u30f3\u30c8\u3092\u767b\u9332\u3059\u308b\ninstance.on(&#039;someEvent&#039;, function(event) {\n  console.log(&#039;Event handler: &#039; + event.type);\n});\n\n\/\/ \u30a4\u30d9\u30f3\u30c8\u3092\u767a\u706b\u3059\u308b\ninstance.fire({\n  type: &#039;someEvent&#039;\n});\n<\/code><\/pre>\n\n\n\n<script type=\"text\/javascript\">\njQuery(function($){\n$(\".jp-video\").hide();\n});\n<\/script>\n","protected":false},"excerpt":{"rendered":"<p>JavaScript the good parts P64\uff5e65\u306b\u8f09\u3063\u3066\u3044\u308beventuality\u95a2\u6570\u306b\u3064\u3044\u3066\u66f8\u3044\u3066\u3044\u304f\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[3],"tags":[],"class_list":["post-4913","post","type-post","status-publish","format-standard","hentry","category-javascript"],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/attacktube.com\/index.php?rest_route=\/wp\/v2\/posts\/4913","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/attacktube.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/attacktube.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/attacktube.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/attacktube.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4913"}],"version-history":[{"count":4,"href":"https:\/\/attacktube.com\/index.php?rest_route=\/wp\/v2\/posts\/4913\/revisions"}],"predecessor-version":[{"id":4919,"href":"https:\/\/attacktube.com\/index.php?rest_route=\/wp\/v2\/posts\/4913\/revisions\/4919"}],"wp:attachment":[{"href":"https:\/\/attacktube.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4913"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/attacktube.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4913"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/attacktube.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4913"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}