{"id":1323,"date":"2012-05-25T21:51:58","date_gmt":"2012-05-25T13:51:58","guid":{"rendered":"http:\/\/leegorous.net\/blog\/?p=1323"},"modified":"2012-05-26T17:55:11","modified_gmt":"2012-05-26T09:55:11","slug":"a-good-javascript-format","status":"publish","type":"post","link":"http:\/\/leegorous.net\/blog\/2012\/05\/25\/a-good-javascript-format\/","title":{"rendered":"\u4e0d\u9519\u7684 JavaScript \u683c\u5f0f"},"content":{"rendered":"<p><a href=\"http:\/\/leegorous.net\/blog\/2012\/05\/25\/a-good-javascript-format\/\"><img loading=\"lazy\" src=\"http:\/\/leegorous.net\/blog\/wp-content\/uploads\/2012\/05\/tooltip.png\" alt=\"\" title=\"tooltip\" width=\"192\" height=\"119\" class=\"alignright size-full wp-image-1325\" \/><\/a>\u5728\u91cd\u5236 <a href=\"http:\/\/leegorous.net\/tools\/gen-pwd.html\">\u5728\u7ebf\u5bc6\u7801\u751f\u6210\u5668<\/a> \u8fd9\u4e2a\u5355\u9875\u5de5\u5177\u65f6\uff0c\u5c1d\u8bd5\u7684\u4e00\u79cd\u4ea4\u4e92\u65b9\u5f0f\u9700\u8981 <a href=\"http:\/\/twitter.github.com\/bootstrap\/javascript.html#tooltips\">tooltip<\/a> (\u6765\u81ea <a href=\"http:\/\/twitter.github.com\/bootstrap\/\">Bootstrap<\/a>) \u4f5c\u4e3a\u64cd\u4f5c\u63d0\u793a\u7684\u8f7d\u4f53\uff0c\u52a8\u6001\u4fee\u6539 tooltip \u7684\u5185\u5bb9\u3002\u4e8e\u662f\u67e5\u9605\u4e86\u5176 <a href=\"https:\/\/github.com\/twitter\/bootstrap\/blob\/master\/js\/bootstrap-tooltip.js\">\u6e90\u4ee3\u7801<\/a>\uff0c\u867d\u7136\u6ca1\u53d1\u73b0\u6709\u8fd9\u6837\u7684\u529f\u80fd\u652f\u6301\uff08\u540e\u6765\u5c0f\u6539\u4e86\u4e00\u884c\u4e4b\u540e\u5c31\u53ef\u4ee5\u4e86\uff09\uff0c\u4f46\u662f\u5374\u53d1\u73b0\u5176\u4ee3\u7801\u683c\u5f0f\u6709\u4e9b\u6709\u8da3\u7684\u5730\u65b9\u3002<\/p>\n<pre class=\"brush: javascript\">\r\nTooltip.prototype = {\r\n\r\n  constructor: Tooltip\r\n\r\n, init: function (type, element, options) {\r\n    var eventIn\r\n      , eventOut\r\n\r\n    this.type = type\r\n    \/\/ ...\r\n    this.options.selector ?\r\n      (this._options = $.extend({}, this.options, { trigger: &#039;manual&#039;, selector: &#039;&#039; })) :\r\n      this.fixTitle()\r\n    }\r\n\/\/ ...\r\n}\r\n<\/pre>\n<p>\u53ef\u4ee5\u6ce8\u610f\u5230\u4e0b\u9762\u51e0\u70b9\uff1a<!--more--><\/p>\n<h2>\u4e0d\u5199\u5206\u53f7<\/h2>\n<p>\u5728\u5199\u6e90\u4ee3\u7801\u7684\u65f6\u5019\uff0c\u6ca1\u6709\u8fd9\u4e2a\u5206\u53f7\uff0c\u9664\u4e86\u4ee3\u7801\u66f4\u52a0\u5e72\u51c0\u4e4b\u5916\uff0c\u4fee\u6539\u7684\u65f6\u5019\u4e5f\u66f4\u5c11\u8d1f\u62c5\u3002\u6bd4\u5982\u76f4\u63a5\u5728\u884c\u672b\u7eed\u52a0\u4ee3\u7801\uff0c\u6216\u8005\uff0c\u56e0\u4e3a\u7f16\u8f91\u5668\u6709\u5404\u79cd\u5feb\u6377\u952e\u8ddf\u884c\u672b\u6709\u5173\uff0c\u800c\u4e0d\u4f1a\u8ddf\u884c\u672b\u7684\u5206\u53f7\u6709\u5173\uff0c\u5728\u505a\u50cf\u5c06\u540e\u9762\u7684\u4ee3\u7801\u9700\u8981\u6362\u5230\u524d\u9762\u7b49\u7684\u8c03\u6574\u64cd\u4f5c\u65f6\u90fd\u66f4\u6709\u5229\u3002<\/p>\n<p>\u867d\u7136\u6bcf\u6b21\u53ea\u662f\u5c11\u4e00\u6b21\u6309\u952e\uff0c\u5199\u6210\u5343\u4e0a\u4e07\u884c\u4ee3\u7801\u7d2f\u79ef\u8d77\u6765\u4e5f\u975e\u5e38\u53ef\u89c2\u3002<\/p>\n<p>OK\uff0c\u4e0d\u5199\u5206\u53f7\u4e5f\u662f\u6709\u4e00\u5b9a <a href=\"http:\/\/google-styleguide.googlecode.com\/svn\/trunk\/javascriptguide.xml?showone=Semicolons#Semicolons\">\u526f\u4f5c\u7528<\/a> \u7684\u3002\u4f5c\u4e3a\u8865\u5145\uff0c\u5982\u679c\u8981\u5199\u5206\u53f7\uff0c\u53ea\u9700\u8981\u52a0\u5728\u4ee5 <code>'(', '[', '+', '-'<\/code> \u5f00\u5934\u7684\u884c\u7684\u884c\u9996\u3002\u6240\u4ee5\u4f1a\u770b\u89c1\u8fd9\u6837\u7684\u4ee3\u7801<\/p>\n<pre class=\"brush: javascript\">\r\n;(function() { \r\n  \/* function body *\/ \r\n})()\r\n<\/pre>\n<h2>\u5bf9\u8c61\uff0c\u6570\u7ec4\uff0cvar \u53d8\u91cf\u58f0\u660e\u4e2d\u6bcf\u9879\u90fd\u72ec\u5360\u4e00\u884c\uff0c\u800c\u4e14\u9017\u53f7\u662f\u5199\u5728\u4e0b\u4e00\u9879\u4e4b\u524d<\/h2>\n<p>\u901a\u5e38\u6211\u5199\u6570\u7ec4\u7684\u65f6\u5019\u662f\u8fd9\u6837\u7684\uff0c\u9017\u53f7\u662f\u8ddf\u5728\u524d\u4e00\u9879\u7684\u540e\u9762\u3002<\/p>\n<pre class=\"brush: javascript\">\r\n[\r\n  &#039;string&#039;,\r\n  &#039;number&#039;,\r\n  &#039;boolean&#039;\r\n]\r\n<\/pre>\n<p>\u8fd9\u6837\u5199\u5982\u679c\u8981\u7eed\u52a0\u9879\uff0c\u9700\u8981\u5728\u6700\u540e\u4e00\u9879\u4e4b\u540e\u52a0\u9017\u53f7\uff0c\u7136\u540e\u6362\u884c\u3002\u5b83\u90a3\u6837\u5c31\u90fd\u5199\u5728\u4e00\u884c\u91cc\uff0c\u867d\u7136\u6309\u952e\u6b21\u6570\u662f\u76f8\u540c\u7684\u3002\u800c\u82e5\u9700\u8981\u5c06\u4e2d\u95f4\u7684\u9879\u9700\u8981\u4e0e\u672b\u9879\u4ea4\u6362\u65f6\uff0c\u8fd9\u6837\u5199\u5728\u4ea4\u6362\u4e4b\u540e\uff0c\u8fd8\u9700\u8981\u4fee\u6539\u8fd9\u4e24\u884c\u884c\u672b\u7684\u9017\u53f7\uff0c\u5b83\u90a3\u6837\u5199\u5219\u4ea4\u6362\u5b8c\u884c\u540e\u5c31\u5b8c\u4e8b\u4e86\u3002\u6ca1\u6709\u591a\u4f59\u52a8\u4f5c\u3002\u4f46\u662f\uff0c\u9488\u65e0\u4e24\u5934\u5229\uff0c\u82e5\u662f\u4e0e\u9996\u9879\u4ea4\u6362\u7684\uff0c\u884c\u9996\u7684\u9017\u53f7\u8fd8\u662f\u9700\u8981\u989d\u5916\u52a8\u4f5c\u3002\u4f60\u8ba4\u4e3a\u662f\u6d89\u53ca\u672b\u9879\u7684\u4fee\u6539\u4e0e\u6d89\u53ca\u9996\u9879\u7684\u4fee\u6539\u54ea\u4e2a\u66f4\u591a\u5462\uff1f<\/p>\n<p>\u884c\u672b\u4e0d\u8ddf\u9017\u53f7\uff0c\u4e0e\u884c\u672b\u4e0d\u8ddf\u5206\u53f7\u4e00\u6837\uff0c\u6709\u7740\u540c\u6837\u7684\u4fbf\u5229\u3002\u6574\u4f53\u98ce\u683c\u4e5f\u66f4\u52a0\u4e00\u81f4\u3002<\/p>\n<h2>\u4e0d\u540c\u7c7b\u8bed\u53e5\u4e4b\u95f4\u90fd\u6709\u4e2a\u7a7a\u884c<\/h2>\n<p>\u4f7f\u4ee3\u7801\u4e4b\u95f4\u7a7a\u95f4\u66f4\u5927\uff0c\u4fbf\u4e8e\u9605\u8bfb\u3002\u7531\u4e8e\u6ca1\u6709\u884c\u672b\u5206\u53f7\u7684\u5b58\u5728\uff0c\u9700\u8981\u6dfb\u52a0\u9879\u76ee\u65f6\uff0c\u53ef\u4ee5\u76f4\u63a5\u5728\u7a7a\u884c\u4e0a\u5f00\u59cb\uff0c\u7ed3\u675f\u7684\u65f6\u5019\u518d\u8865\u4e0a\u6362\u884c\u3002<\/p>\n<h2>\u6362\u884c\u66f4\u52a0\u4eba\u6027\u5316<\/h2>\n<p>\u5185\u5bb9\u592a\u957f\u7684\u65f6\u5019\uff0c\u9009\u62e9\u6027\u5730\u5c06\u8bed\u4e49\u4e0a\u5c5e\u4e8e\u4e00\u4f53\u7684\u5185\u5bb9\u653e\u5728\u4e00\u884c\u5185\uff0c\u4f7f\u9605\u8bfb\u66f4\u52a0\u6e05\u6670\uff0c\u987a\u7545\u3002<\/p>\n<h2>\u7ed3\u8bed<\/h2>\n<p>\u5982\u679c\u4f60\u88ab\u544a\u77e5\u5728\u5199\u4ee3\u7801\u7684\u65f6\u5019\u8981\u7ef4\u6301\u4e00\u4e2a\u683c\u5f0f\uff0c\u800c\u4e14\u4e00\u4e2a\u683c\u5f0f\u4f1a\u6709\u673a\u4f1a\u8ba9\u4f60\u4ea7\u751f\u9057\u6f0f\uff0c\u751a\u81f3\u9519\u8bef\uff0c\u5373\u4f7f\u7ed3\u679c\u518d\u6807\u51c6\uff0c\u4f60\u5927\u6982\u4e5f\u4f1a\u8ba4\u4e3a\u90a3\u683c\u5f0f\u662f\u79cd\u8d1f\u7d2f\u3002\u4e0a\u9762\u63d0\u5230\u7684\u4e00\u4e9b\u4ee3\u7801\u98ce\u683c\uff0c\u4e5f\u8bb8\u6709\u4e9b\u7f3a\u9677\uff0c\u4f46\u662f\u5728\u63d0\u9192\u6211\u4e00\u4ef6\u4e8b\uff0c<strong>\u6211\u4eec\u662f\u53ef\u4ee5\u7ad9\u5728\u5199\u4ee3\u7801\u7684\u4ea4\u4e92\u8fc7\u7a0b\u7684\u89d2\u5ea6\u53bb\u8003\u8651\uff0c\u53bb\u6bd4\u8f83\uff0c\u662f\u6709\u53ef\u80fd\u5b9e\u5b9e\u5728\u5728\u5730\u51cf\u8d1f\uff0c\u51cf\u5c11\u9519\u8bef\u7684\u53ef\u80fd\uff0c\u800c\u4e14\u51fa\u6765\u7684\u4ee3\u7801\u53c8\u662f\u5e72\u51c0\u8212\u9002\u7684\u3002\u65e0\u8bba\u9694\u591a\u5c11\u4e2a\u6708\u4e4b\u540e\u770b\uff0c\u90a3\uff0c\u90fd\u662f\u6211\u4eec\u81ea\u5df1\u5199\u7684\u4ee3\u7801\u3002<\/strong><\/p>\n<p>\u5bf9\u4e8e\u952e\u76d8\u6d41\u6765\u8bf4\uff0c\u6700\u80fd\u591f\u660e\u767d\u8fc7\u7a0b\u4e2d\u4e00\u70b9\u70b9\u5c0f\u4e0d\u540c\uff0c\u5bf9\u4ee3\u7801\u7f16\u5199\u7684\u60c5\u7eea\u5f71\u54cd\uff0c\u5728\u957f\u65f6\u95f4\u7d2f\u79ef\u4e4b\u540e\u5bf9\u6700\u7ec8\u5f62\u52bf\u7684\u5de8\u5927\u5dee\u522b\u3002<\/p>\n<p><em>PS: \u5982\u679c\u4f60\u4e5f\u60f3\u52a8\u6001\u5730\u4fee\u6539 tooltip \u7684 title\uff0c\u53ef\u4ee5\u53c2\u8003\u8fd9\u4e2a<a href=\"http:\/\/leegorous.net\/css\/bootstrap\/2.0.3\/js\/bootstrap-tooltip.js\">\u4fee\u6539\u540e\u7684\u7248\u672c<\/a><\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u91cd\u5236 \u5728\u7ebf\u5bc6\u7801\u751f\u6210\u5668 \u8fd9\u4e2a\u5355\u9875\u5de5\u5177\u65f6\uff0c\u5c1d\u8bd5\u7684\u4e00\u79cd\u4ea4\u4e92\u65b9\u5f0f\u9700\u8981 tooltip (\u6765\u81ea Bootstrap)  &hellip; <\/p>\n<p class=\"link-more\"><a href=\"http:\/\/leegorous.net\/blog\/2012\/05\/25\/a-good-javascript-format\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u201c\u4e0d\u9519\u7684 JavaScript \u683c\u5f0f\u201d<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[102],"tags":[83,9],"_links":{"self":[{"href":"http:\/\/leegorous.net\/blog\/wp-json\/wp\/v2\/posts\/1323"}],"collection":[{"href":"http:\/\/leegorous.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/leegorous.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/leegorous.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/leegorous.net\/blog\/wp-json\/wp\/v2\/comments?post=1323"}],"version-history":[{"count":10,"href":"http:\/\/leegorous.net\/blog\/wp-json\/wp\/v2\/posts\/1323\/revisions"}],"predecessor-version":[{"id":1330,"href":"http:\/\/leegorous.net\/blog\/wp-json\/wp\/v2\/posts\/1323\/revisions\/1330"}],"wp:attachment":[{"href":"http:\/\/leegorous.net\/blog\/wp-json\/wp\/v2\/media?parent=1323"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/leegorous.net\/blog\/wp-json\/wp\/v2\/categories?post=1323"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/leegorous.net\/blog\/wp-json\/wp\/v2\/tags?post=1323"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}