{"id":12576,"date":"2023-11-28T22:59:04","date_gmt":"2023-11-28T14:59:04","guid":{"rendered":"https:\/\/wx.kaifamiao.info\/?p=12576"},"modified":"2023-11-28T22:59:08","modified_gmt":"2023-11-28T14:59:08","slug":"qian-duan-mian-shi-ticommonjsnode-js-shi-shen-me","status":"publish","type":"post","link":"http:\/\/wx.kaifamiao.info\/index.php\/2023\/11\/28\/qian-duan-mian-shi-ticommonjsnode-js-shi-shen-me\/","title":{"rendered":"\u524d\u7aef\u9762\u8bd5\u9898\uff1aCommonJS-Node. js\u662f\u4ec0\u4e48\uff1f"},"content":{"rendered":"<p>AMD (\u5f02\u6b65\u6a21\u5757\u5b9a\u4e49)-\u6d4f\u89c8\u5668<br \/>\n\u57fa\u672c\u4e0a\uff0c\u4f7f\u7528\u6a21\u5757\u7684\u65b9\u5f0f\u5f88\u7b80\u5355\uff0cimport\u7528\u4e8e\u4ece\u53e6\u4e00\u4e2a\u6587\u4ef6\u4e2d\u83b7\u53d6\u529f\u80fd\u6216\u51e0\u4e2a\u529f\u80fd\u6216\u503c\uff0c\u540c \u65f6export\u7528\u4e8e\u4ece\u6587\u4ef6\u4e2d\u516c\u5f00\u529f\u80fd\u6216\u51e0\u4e2a\u529f\u80fd\u6216\u503c\u3002<br \/>\n\u5bfc\u51fa<br \/>\n\u4f7f\u7528 ES5 (CommonJS)<br \/>\n\/\/ \u4f7f\u7528 ES5 CommonJS &#8211; helpers, js<br \/>\nexports. isNull = function (val) {<br \/>\nreturn val == null\uff1b<br \/>\n}<br \/>\nexports. isUndefined = function (val) {<br \/>\nreturn val = undefined\uff1b<br \/>\n}<br \/>\nexports. isNullOrUndefined = function (val) {<br \/>\nreturn exports. isNull(val) || exports.isUndefined(val)\uff1b }<br \/>\n\u4f7f\u7528ES6\u6a21\u5757 \u4f7f\u7528<br \/>\nES6 Modules &#8211; helpers. js<br \/>\nexport function isNull(val){<br \/>\nreturn val = null\uff1b<br \/>\n}<br \/>\nexport function isUndefined(val) {<br \/>\nreturn val = undefined\uff1b<br \/>\n}<br \/>\nexport function isNullOrUndefined(val) {<br \/>\nreturn isNull(val) || isUndefined(val)\uff1b<br \/>\n}<\/p>\n<p>\u5728\u53e6\u4e00\u4e2a\u6587\u4ef6\u4e2d\u5bfc\u5165\u51fd\u6570<br \/>\n\/\/ \u4f7f\u7528 ES5 (CommonJS) &#8211; index. js<br \/>\nconst helpers = require(&#8216;. \/helpers.js&#8217;)\uff1b \/\/ helpers is an object<br \/>\nconst isNull = helpers. isNull\uff1b<br \/>\nconst isUndefined = helpers. isUndefined\uff1b<br \/>\nconst isNullOrUndef ined = helpers. isNullOrUndefined\uff1b<br \/>\n\/\/ or if your environment supports Destructuring<br \/>\nconst { isNull, isUndefined, isNullOrUndefined } = require(&#8216;.\/helpers, js&#8217;)\uff1b<br \/>\n\/\/ ES6 Modules &#8211; index, js<br \/>\nimport * as helpers from &#8216;. \/helpers.js&#8217;\uff1b \/\/ helpers is an object<br \/>\n\/\/ or<br \/>\nimport { isNull, isUndefined, isNullOrUndefined as isValid } from &#8216;. \/helpers.js&#8217;\uff1b<br \/>\n\/\/ using &quot;as&quot; for renaming named exports<br \/>\n\u5728\u6587\u4ef6\u4e2d\u5bfc\u51fa\u5355\u4e2a\u529f\u80fd\u6216\u9ed8\u8ba4\u5bfc\u51fa<br \/>\n\u4f7f\u7528 ES5 (CommonJS)<br \/>\n\/\/ \u4f7f\u7528 ES5 (CommonJS) &#8211; index. js<br \/>\nclass Helpers {<br \/>\nstatic isNull(val) {<br \/>\nreturn val == null\uff1b<br \/>\n}<br \/>\nstatic isUndefined(val) {<br \/>\nreturn val == undefined\uff1b<br \/>\n}<br \/>\nstatic isNu1lOrUndefined(va1) {<br \/>\nreturn this. isNull(val) || this.isUndefined(val)\uff1b<br \/>\n)<br \/>\n}<br \/>\nmodule. exports = Helpers\uff1b<br \/>\n\u4f7f\u7528 ES6 Modules<br \/>\n\/\/ \u4f7f\u7528 ES6 Modules &#8211; helpers. js<br \/>\nclass Helpers {<br \/>\nstatic isNull(val) {<br \/>\nreturn val == null\uff1b<br \/>\n}<br \/>\nstatic isUndefined(val) {<br \/>\nreturn val = undefined\uff1b<br \/>\n}<br \/>\nstatic isNullOrUndefined(val) {<br \/>\nreturn this. isNull(val) || this.isUndefined(val)\uff1b<br \/>\n}<br \/>\n}<br \/>\nexport default Helpers<br \/>\n\u4ece\u53e6\u4e00\u4e2a\u6587\u4ef6\u5bfc\u5165\u5355\u4e2a\u529f\u80fd<br \/>\n\u4f7f\u7528 ES5 (CommonJS)<br \/>\n\/\/ \u4f7f\u7528 ES5 (CommonJS) &#8211; index. js const Helpers = require(&#8216;. \/helpers. js&#8217;);<br \/>\nconsole. log(Helpers. isNull(null))\uff1b<br \/>\n\u4f7f\u7528 ES6 Modules<br \/>\nimport Helpers from &#8216;.helpers.js&#8217; console. log(Helpers. isNull(null))\uff1b<\/p>\n","protected":false},"excerpt":{"rendered":"<p>AMD (\u5f02\u6b65\u6a21\u5757\u5b9a\u4e49)-\u6d4f\u89c8\u5668 \u57fa\u672c\u4e0a\uff0c\u4f7f\u7528\u6a21\u5757\u7684\u65b9\u5f0f\u5f88\u7b80\u5355\uff0cimport\u7528\u4e8e\u4ece\u53e6\u4e00\u4e2a\u6587\u4ef6\u4e2d\u83b7\u53d6\u529f\u80fd\u6216\u51e0\u4e2a\u529f [&hellip;]<\/p>\n","protected":false},"author":8,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[103],"tags":[],"class_list":["post-12576","post","type-post","status-publish","format-standard","hentry","category-qianduan"],"_links":{"self":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/12576","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/users\/8"}],"replies":[{"embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/comments?post=12576"}],"version-history":[{"count":1,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/12576\/revisions"}],"predecessor-version":[{"id":12577,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/12576\/revisions\/12577"}],"wp:attachment":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/media?parent=12576"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/categories?post=12576"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/tags?post=12576"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}