{"id":415671,"date":"2024-06-30T00:30:43","date_gmt":"2024-06-30T00:30:43","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=415671"},"modified":"-0001-11-30T00:00:00","modified_gmt":"2024-06-30T00:30:43","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=415671","title":{"rendered":"<span>Namespaces \u0432 JavaScript. \u0421\u0442\u0430\u0432\u0438\u043c \u0442\u043e\u0447\u043a\u0443 \u0432 \u0432\u043e\u043f\u0440\u043e\u0441\u0435<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/2c7\/7b4\/fa7\/2c77b4fa7cc5419a2605147376e383e8.jpg\" width=\"1000\" height=\"904\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/2c7\/7b4\/fa7\/2c77b4fa7cc5419a2605147376e383e8.jpg\" data-blurred=\"true\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0420\u0430\u0437\u0432\u0438\u0442\u0438\u0435 \u044f\u0437\u044b\u043a\u0430 javascript \u043f\u0435\u0440\u0435\u043d\u043e\u0441\u0438\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043a\u043e\u0434\u043e\u0432 \u043d\u0430 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u0443\u044e \u0441\u0435\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0438 \u0441\u043d\u0438\u043c\u0430\u0435\u0442 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0443 \u0441 \u0441\u0435\u0440\u0432\u0435\u0440\u0430. \u042d\u0442\u043e \u0440\u0430\u0437\u0443\u043c\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434. \u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0432 js \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u0445 \u0441\u043b\u043e\u0432 class, extends \u0438 static \u0434\u0430\u043b\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043b\u0435\u0433\u043a\u043e \u043c\u043e\u0434\u0435\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043b\u0430\u0441\u0441\u0430\u043c\u0438 \u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c\u0438 \u043f\u0440\u0435\u0434\u043c\u0435\u0442\u043d\u0443\u044e \u043e\u0431\u043b\u0430\u0441\u0442\u044c \u043f\u0440\u043e\u0435\u043a\u0442\u0430. \u042d\u0442\u043e \u0437\u0430\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u043e. \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0432\u043e\u043f\u0440\u043e\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043f\u0440\u0438 \u0432\u043e\u0437\u0440\u0430\u0441\u0442\u0430\u043d\u0438\u0438 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u0438 js-\u043f\u0440\u043e\u0435\u043a\u0442\u0430 &#8212; \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u043e \u0438\u043c\u0435\u043d. \u0418\u043c\u0435\u043d\u043d\u043e \u043e\u043d\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u043a\u043e\u043d\u0444\u043b\u0438\u043a\u0442\u043e\u0432 \u0441 \u0432\u043e\u0440\u043e\u0445\u043e\u043c \u0440\u0430\u0437\u043d\u043e\u0440\u043e\u0434\u043d\u044b\u0445 js-\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0432. \u041a\u0430\u043a \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0430 \u0441 \u044d\u0442\u0438\u043c \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u043c \u043f\u043e\u0447\u0435\u043c\u0443-\u0442\u043e \u0432\u043e\u0437\u043d\u0438\u043a\u043b\u0438 \u0431\u043e\u043b\u044c\u0448\u0438\u0435 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u0438. \u0421\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0438\u0436\u0435:<\/p>\n<p><a href=\"https:\/\/support.qbpro.ru\/index.php?title=%D0%91%D0%B0%D0%B7%D0%BE%D0%B2%D1%8B%D0%B5_Namespace_%D0%BF%D0%B0%D1%82%D1%82%D0%B5%D1%80%D0%BD%D1%8B_JavaScript\" rel=\"noopener noreferrer nofollow\">https:\/\/support.qbpro.ru\/index.php?title=\u0411\u0430\u0437\u043e\u0432\u044b\u0435_Namespace_\u043f\u0430\u0442\u0442\u0435\u0440\u043d\u044b_JavaScript<\/a><\/p>\n<p> <a href=\"https:\/\/habr.com\/ru\/post\/527610\/\" rel=\"noopener noreferrer nofollow\">https:\/\/habr.com\/ru\/post\/527610\/<\/a><\/p>\n<p><a href=\"https:\/\/drbrain.ru\/articles\/js-namespaces\/\" rel=\"noopener noreferrer nofollow\">https:\/\/drbrain.ru\/articles\/js-namespaces\/<\/a><\/p>\n<p><a href=\"https:\/\/stackoverflow.com\/questions\/881515\/how-do-i-declare-a-namespace-in-javascript\" rel=\"noopener noreferrer nofollow\">https:\/\/stackoverflow.com\/questions\/881515\/how-do-i-declare-a-namespace-in-javascript<\/a><\/p>\n<p>\u041f\u043b\u043e\u0445\u043e, \u0442\u043e\u043b\u044c\u043a\u043e \u0437\u0430\u043f\u0443\u0442\u0430\u043b\u0438 \u0432\u0441\u0435 \u0438 \u043c\u043d\u043e\u0433\u0438\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0441\u043b\u043e\u0436\u043d\u044b.<\/p>\n<p>\u0415\u0441\u0442\u044c \u0435\u0449\u0435 \u0438 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u0430\u044f \u0441\u0445\u0435\u043c\u0430 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c import, export \u043c\u043e\u0434\u0443\u043b\u0435\u0439:<\/p>\n<p><a href=\"https:\/\/learn.javascript.ru\/modules-intro\" rel=\"noopener noreferrer nofollow\">https:\/\/learn.javascript.ru\/modules-intro<\/a><\/p>\n<p><a href=\"https:\/\/habr.com\/ru\/company\/domclick\/blog\/532084\/\" rel=\"noopener noreferrer nofollow\">https:\/\/habr.com\/ru\/company\/domclick\/blog\/532084\/<\/a><\/p>\n<p>\u0417\u0430 \u043c\u043e\u0434\u0443\u043b\u044f\u043c\u0438 \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u0431\u0443\u0434\u0443\u0449\u0435\u0435, \u043d\u043e \u0441 \u043d\u0438\u043c\u0438 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u043f\u0430\u0440\u0430 \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432 &#8212; \u044d\u0442\u043e \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u0435 \u0438\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0431\u0435\u0437 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 (CORS policy), \u0430 \u0433\u043b\u0430\u0432\u043d\u043e\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 \u0438\u0445 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0430\u043c\u0438  \u0432\u0441\u0435 \u0435\u0449\u0435 \u043d\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0430 (\u043c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u043e web-workers \u043d\u0435 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u043c\u043e\u0434\u0443\u043b\u0438, \u0441\u0442\u0430\u0440\u044b\u0435 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u044b \u0442\u043e\u0436\u0435 \u043d\u0435 \u043f\u043e\u043d\u0438\u043c\u0430\u044e\u0442):<\/p>\n<p><a href=\"https:\/\/developer.mozilla.org\/ru\/docs\/Web\/JavaScript\/Guide\/Modules\" rel=\"noopener noreferrer nofollow\">https:\/\/developer.mozilla.org\/ru\/docs\/Web\/JavaScript\/Guide\/Modules<\/a><\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/852\/a13\/78a\/852a1378a9d9d308ff14a02798874501.png\" width=\"935\" height=\"747\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/852\/a13\/78a\/852a1378a9d9d308ff14a02798874501.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u044b\u0439 \u0432\u0435\u0431-worker \u043f\u043e-\u0441\u0432\u043e\u0435\u043c\u0443 \u0437\u0430\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0441\u043a\u0440\u0438\u043f\u0442\u044b:<\/p>\n<p><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/WorkerGlobalScope\/importScripts\" rel=\"noopener noreferrer nofollow\">https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/WorkerGlobalScope\/importScripts<\/a><\/p>\n<p>\u041b\u0430\u0434\u043d\u043e, \u0443\u0447\u0442\u0435\u043c \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438 \u0438 \u0432\u044b\u0431\u0435\u0440\u0435\u043c \u0434\u043b\u044f \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u0441\u0445\u0435\u043c\u0443 (\u043f\u0430\u0442\u0442\u0435\u0440\u043d) \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0430 \u0438\u043c\u0435\u043d, \u0442\u0430\u043a\u0443\u044e \u0447\u0442\u043e \u043c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u044b\u0435 workers \u0431\u0443\u0434\u0443\u0442 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u044b \u0438 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442 \u0437\u0430\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442. \u0414\u043b\u044f \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c\u0441\u044f \u043d\u0430 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0435 \u0433\u0434\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0442\u0440\u0435\u043b\u043e\u0447\u0435\u043a, \u0441\u043a\u043e\u0431\u043e\u0447\u0435\u043a \u0438 \u043f\u0440\u043e\u0447\u0438\u0445 \u0437\u0430\u0441\u043e\u0440\u044f\u044e\u0449\u0438\u0445 \u0447\u0435\u043b\u043e\u0432\u0435\u0447\u0435\u0441\u043a\u043e\u0435 \u0432\u043e\u0441\u043f\u0440\u0438\u044f\u0442\u0438\u0435 \u0437\u0430\u043a\u043e\u0440\u044e\u0447\u0435\u043a \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e. <\/p>\n<pre><code class=\"javascript\">\/**   * @namespace namespaceOne  *\/ const namespaceOne = new function(){         class First {         \/\/\u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e         static className = \"First\";         constructor() {             console.log(\"class First consructed\");         }          print() {             console.log(\"First print\");         }          \/\/\u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f         static printStatic() {             console.log(First.className + \" static print \");         }     }      \/\/\u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435     class Second extends First {         constructor() {             super();             Second.className = \"Second\";             console.log(\"class Second consructed\");         }         \/\/\u043f\u043e\u043b\u0438\u043c\u043e\u0440\u0444\u0438\u0437\u043c         print() {             console.log(Second.className + \" print\");         }     }      class Third {         className;         encapsulation;         constructor() {             this.className = \"Third\";             this.encapsulation = new Second(); \/\/\u0438\u043d\u043a\u0430\u043f\u0441\u0443\u043b\u044f\u0446\u0438\u044f             console.log(\"class Third consructed\");         }         print() {             console.log(\"Third print\");         }     }     console.log(\"namespaceOne code done\");     \/\/\u044d\u043a\u0441\u043f\u043e\u0440\u0442 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0430 \u0438\u043c\u0435\u043d     return {First: First, Second: Second, Third: Third}; };  \/**   * @namespace namespaceTwo  *\/ const namespaceTwo = new function(){         class First {                 constructor() {             console.log(\"other class First consructed\");         }          print() {             console.log(\"other First print\");         }            }     \/\/\u044d\u043a\u0441\u043f\u043e\u0440\u0442 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0430 \u0438\u043c\u0435\u043d     return {First: First}; };  \/**   * @namespace namespaceThree  *\/ const namespaceThree = new function(){     \/\/\u0438\u043c\u043f\u043e\u0440\u0442 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0430 \u0438\u043c\u0435\u043d     namespaceOne.First.printStatic();     let second = new namespaceOne.Second();     second.print();      let ThirdClass = namespaceOne.Third;     let third = new ThirdClass();     third.print();          let first1 = new namespaceOne.First();     let first2 = new namespaceTwo.First();     first1.print();     first2.print(); };<\/code><\/pre>\n<p> \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u0441\u043c\u0435\u043b\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u0432\u0430\u0448 \u043a\u043e\u0434 \u0432 \u043b\u044e\u0431\u043e\u0439 \u043f\u0440\u043e\u0435\u043a\u0442. \u0421 \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c\u044e \u043a\u043e\u043d\u0444\u043b\u0438\u043a\u0442\u043e\u0432 \u043d\u0435 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u0435\u0442. \u041c\u0438\u043d\u0443\u0441 \u0442\u0430\u043a\u043e\u0433\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u044f: \u043d\u0430\u0434\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438, \u0447\u0442\u043e \u0432\u043e\u0442 \u0442\u0430\u043a\u0438\u0435 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438: <code>const namespaceYou = new function(){...} - <\/code>\u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f namespace, \u0430 \u043d\u0435 \u0447\u0443\u0434\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439.<\/p>\n<p>\u0415\u0441\u0442\u044c \u0438 \u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u043d\u0435 \u0437\u0430\u0441\u043e\u0440\u044f\u0442\u044c \u043e\u0431\u0449\u0435\u0435 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u043e \u043a\u043e\u0434\u043e\u043c (\u043d\u0435\u043a\u043e\u0442\u043e\u0440\u0430\u044f \u044d\u043a\u043e\u043b\u043e\u0433\u0438\u0447\u043d\u043e\u0441\u0442\u044c \u0442\u0430\u043a \u0441\u043a\u0430\u0437\u0430\u0442\u044c) &#8212; \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u0437\u044f\u0442\u044c \u0432\u0430\u0448 \u043a\u043e\u0434 \u0432 \u0444\u0438\u0433\u0443\u0440\u043d\u044b\u0435 \u0441\u043a\u043e\u0431\u043a\u0438 { } \u0438 \u043d\u0435 \u0437\u043b\u043e\u0443\u043f\u043e\u0442\u0440\u0435\u0431\u043b\u044f\u0442\u044c \u043c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0430\u043c\u0438 var \u0438 function:<\/p>\n<pre><code class=\"javascript\">{ \/\/namespace1     class Simple {         constructor() {             console.log(\"Simple created\");         }         print() {             console.log(\"Simple called\");         }     }      let simple = new Simple();      \/\/\u044d\u043a\u0441\u043f\u043e\u0440\u0442      var namespace1 = {simpleObject: simple, SimpleClass: Simple}; }  {\/\/namespace2     namespace1.simpleObject.print();     let simple = new namespace1.SimpleClass(); }<\/code><\/pre>\n<p>\u041a\u0440\u0430\u0441\u043e\u0442\u0430.<\/p>\n<p>\u041a\u043e\u0433\u0434\u0430 \u043d\u0438\u0431\u0443\u0434\u044c \u0432\u0435\u0431-workers \u043d\u0430\u0447\u043d\u0443\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u043c\u043e\u0434\u0443\u043b\u044f\u043c\u0438, \u0430 CORS policy \u0440\u0430\u0437\u0440\u0435\u0448\u0438\u0442 \u043f\u0438\u0441\u0430\u0442\u044c \u0432\u0430\u043c \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0435 \u043c\u043e\u0434\u0443\u043b\u044c\u043d\u044b\u0435 js-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0438 \u0432\u0441\u0435 \u044d\u0442\u043e \u0443\u0439\u0434\u0451\u0442 \u0432 \u0438\u0441\u0442\u043e\u0440\u0438\u044e. \u041a\u043e\u0433\u0434\u0430-\u043d\u0438\u0431\u0443\u0434\u044c &#8230;<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/583130\/\"> https:\/\/habr.com\/ru\/articles\/583130\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0420\u0430\u0437\u0432\u0438\u0442\u0438\u0435 \u044f\u0437\u044b\u043a\u0430 javascript \u043f\u0435\u0440\u0435\u043d\u043e\u0441\u0438\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043a\u043e\u0434\u043e\u0432 \u043d\u0430 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u0443\u044e \u0441\u0435\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0438 \u0441\u043d\u0438\u043c\u0430\u0435\u0442 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0443 \u0441 \u0441\u0435\u0440\u0432\u0435\u0440\u0430. \u042d\u0442\u043e \u0440\u0430\u0437\u0443\u043c\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434. \u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0432 js \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u0445 \u0441\u043b\u043e\u0432 class, extends \u0438 static \u0434\u0430\u043b\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043b\u0435\u0433\u043a\u043e \u043c\u043e\u0434\u0435\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043b\u0430\u0441\u0441\u0430\u043c\u0438 \u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c\u0438 \u043f\u0440\u0435\u0434\u043c\u0435\u0442\u043d\u0443\u044e \u043e\u0431\u043b\u0430\u0441\u0442\u044c \u043f\u0440\u043e\u0435\u043a\u0442\u0430. \u042d\u0442\u043e \u0437\u0430\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u043e. \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0432\u043e\u043f\u0440\u043e\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043f\u0440\u0438 \u0432\u043e\u0437\u0440\u0430\u0441\u0442\u0430\u043d\u0438\u0438 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u0438 js-\u043f\u0440\u043e\u0435\u043a\u0442\u0430 &#8212; \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u043e \u0438\u043c\u0435\u043d. \u0418\u043c\u0435\u043d\u043d\u043e \u043e\u043d\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u043a\u043e\u043d\u0444\u043b\u0438\u043a\u0442\u043e\u0432 \u0441 \u0432\u043e\u0440\u043e\u0445\u043e\u043c \u0440\u0430\u0437\u043d\u043e\u0440\u043e\u0434\u043d\u044b\u0445 js-\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0432. \u041a\u0430\u043a \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0430 \u0441 \u044d\u0442\u0438\u043c \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u043c \u043f\u043e\u0447\u0435\u043c\u0443-\u0442\u043e \u0432\u043e\u0437\u043d\u0438\u043a\u043b\u0438 \u0431\u043e\u043b\u044c\u0448\u0438\u0435 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u0438. \u0421\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0438\u0436\u0435:<\/p>\n<p><a href=\"https:\/\/support.qbpro.ru\/index.php?title=%D0%91%D0%B0%D0%B7%D0%BE%D0%B2%D1%8B%D0%B5_Namespace_%D0%BF%D0%B0%D1%82%D1%82%D0%B5%D1%80%D0%BD%D1%8B_JavaScript\" rel=\"noopener noreferrer nofollow\">https:\/\/support.qbpro.ru\/index.php?title=\u0411\u0430\u0437\u043e\u0432\u044b\u0435_Namespace_\u043f\u0430\u0442\u0442\u0435\u0440\u043d\u044b_JavaScript<\/a><\/p>\n<p> <a href=\"https:\/\/habr.com\/ru\/post\/527610\/\" rel=\"noopener noreferrer nofollow\">https:\/\/habr.com\/ru\/post\/527610\/<\/a><\/p>\n<p><a href=\"https:\/\/drbrain.ru\/articles\/js-namespaces\/\" rel=\"noopener noreferrer nofollow\">https:\/\/drbrain.ru\/articles\/js-namespaces\/<\/a><\/p>\n<p><a href=\"https:\/\/stackoverflow.com\/questions\/881515\/how-do-i-declare-a-namespace-in-javascript\" rel=\"noopener noreferrer nofollow\">https:\/\/stackoverflow.com\/questions\/881515\/how-do-i-declare-a-namespace-in-javascript<\/a><\/p>\n<p>\u041f\u043b\u043e\u0445\u043e, \u0442\u043e\u043b\u044c\u043a\u043e \u0437\u0430\u043f\u0443\u0442\u0430\u043b\u0438 \u0432\u0441\u0435 \u0438 \u043c\u043d\u043e\u0433\u0438\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0441\u043b\u043e\u0436\u043d\u044b.<\/p>\n<p>\u0415\u0441\u0442\u044c \u0435\u0449\u0435 \u0438 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u0430\u044f \u0441\u0445\u0435\u043c\u0430 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c import, export \u043c\u043e\u0434\u0443\u043b\u0435\u0439:<\/p>\n<p><a href=\"https:\/\/learn.javascript.ru\/modules-intro\" rel=\"noopener noreferrer nofollow\">https:\/\/learn.javascript.ru\/modules-intro<\/a><\/p>\n<p><a href=\"https:\/\/habr.com\/ru\/company\/domclick\/blog\/532084\/\" rel=\"noopener noreferrer nofollow\">https:\/\/habr.com\/ru\/company\/domclick\/blog\/532084\/<\/a><\/p>\n<p>\u0417\u0430 \u043c\u043e\u0434\u0443\u043b\u044f\u043c\u0438 \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u0431\u0443\u0434\u0443\u0449\u0435\u0435, \u043d\u043e \u0441 \u043d\u0438\u043c\u0438 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u043f\u0430\u0440\u0430 \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432 &#8212; \u044d\u0442\u043e \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u0435 \u0438\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0431\u0435\u0437 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 (CORS policy), \u0430 \u0433\u043b\u0430\u0432\u043d\u043e\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 \u0438\u0445 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0430\u043c\u0438  \u0432\u0441\u0435 \u0435\u0449\u0435 \u043d\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0430 (\u043c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u043e web-workers \u043d\u0435 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u043c\u043e\u0434\u0443\u043b\u0438, \u0441\u0442\u0430\u0440\u044b\u0435 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u044b \u0442\u043e\u0436\u0435 \u043d\u0435 \u043f\u043e\u043d\u0438\u043c\u0430\u044e\u0442):<\/p>\n<p><a href=\"https:\/\/developer.mozilla.org\/ru\/docs\/Web\/JavaScript\/Guide\/Modules\" rel=\"noopener noreferrer nofollow\">https:\/\/developer.mozilla.org\/ru\/docs\/Web\/JavaScript\/Guide\/Modules<\/a><\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u041c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u044b\u0439 \u0432\u0435\u0431-worker \u043f\u043e-\u0441\u0432\u043e\u0435\u043c\u0443 \u0437\u0430\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0441\u043a\u0440\u0438\u043f\u0442\u044b:<\/p>\n<p><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/WorkerGlobalScope\/importScripts\" rel=\"noopener noreferrer nofollow\">https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/WorkerGlobalScope\/importScripts<\/a><\/p>\n<p>\u041b\u0430\u0434\u043d\u043e, \u0443\u0447\u0442\u0435\u043c \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438 \u0438 \u0432\u044b\u0431\u0435\u0440\u0435\u043c \u0434\u043b\u044f \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u0441\u0445\u0435\u043c\u0443 (\u043f\u0430\u0442\u0442\u0435\u0440\u043d) \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0430 \u0438\u043c\u0435\u043d, \u0442\u0430\u043a\u0443\u044e \u0447\u0442\u043e \u043c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u044b\u0435 workers \u0431\u0443\u0434\u0443\u0442 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u044b \u0438 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442 \u0437\u0430\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442. \u0414\u043b\u044f \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c\u0441\u044f \u043d\u0430 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0435 \u0433\u0434\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0442\u0440\u0435\u043b\u043e\u0447\u0435\u043a, \u0441\u043a\u043e\u0431\u043e\u0447\u0435\u043a \u0438 \u043f\u0440\u043e\u0447\u0438\u0445 \u0437\u0430\u0441\u043e\u0440\u044f\u044e\u0449\u0438\u0445 \u0447\u0435\u043b\u043e\u0432\u0435\u0447\u0435\u0441\u043a\u043e\u0435 \u0432\u043e\u0441\u043f\u0440\u0438\u044f\u0442\u0438\u0435 \u0437\u0430\u043a\u043e\u0440\u044e\u0447\u0435\u043a \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e. <\/p>\n<pre><code class=\"javascript\">\/**   * @namespace namespaceOne  *\/ const namespaceOne = new function(){         class First {         \/\/\u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e         static className = \"First\";         constructor() {             console.log(\"class First consructed\");         }          print() {             console.log(\"First print\");         }          \/\/\u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f         static printStatic() {             console.log(First.className + \" static print \");         }     }      \/\/\u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435     class Second extends First {         constructor() {             super();             Second.className = \"Second\";             console.log(\"class Second consructed\");         }         \/\/\u043f\u043e\u043b\u0438\u043c\u043e\u0440\u0444\u0438\u0437\u043c         print() {             console.log(Second.className + \" print\");         }     }      class Third {         className;         encapsulation;         constructor() {             this.className = \"Third\";             this.encapsulation = new Second(); \/\/\u0438\u043d\u043a\u0430\u043f\u0441\u0443\u043b\u044f\u0446\u0438\u044f             console.log(\"class Third consructed\");         }         print() {             console.log(\"Third print\");         }     }     console.log(\"namespaceOne code done\");     \/\/\u044d\u043a\u0441\u043f\u043e\u0440\u0442 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0430 \u0438\u043c\u0435\u043d     return {First: First, Second: Second, Third: Third}; };  \/**   * @namespace namespaceTwo  *\/ const namespaceTwo = new function(){         class First {                 constructor() {             console.log(\"other class First consructed\");         }          print() {             console.log(\"other First print\");         }            }     \/\/\u044d\u043a\u0441\u043f\u043e\u0440\u0442 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0430 \u0438\u043c\u0435\u043d     return {First: First}; };  \/**   * @namespace namespaceThree  *\/ const namespaceThree = new function(){     \/\/\u0438\u043c\u043f\u043e\u0440\u0442 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0430 \u0438\u043c\u0435\u043d     namespaceOne.First.printStatic();     let second = new namespaceOne.Second();     second.print();      let ThirdClass = namespaceOne.Third;     let third = new ThirdClass();     third.print();          let first1 = new namespaceOne.First();     let first2 = new namespaceTwo.First();     first1.print();     first2.print(); };<\/code><\/pre>\n<p> \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u0441\u043c\u0435\u043b\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u0432\u0430\u0448 \u043a\u043e\u0434 \u0432 \u043b\u044e\u0431\u043e\u0439 \u043f\u0440\u043e\u0435\u043a\u0442. \u0421 \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c\u044e \u043a\u043e\u043d\u0444\u043b\u0438\u043a\u0442\u043e\u0432 \u043d\u0435 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u0435\u0442. \u041c\u0438\u043d\u0443\u0441 \u0442\u0430\u043a\u043e\u0433\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u044f: \u043d\u0430\u0434\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438, \u0447\u0442\u043e \u0432\u043e\u0442 \u0442\u0430\u043a\u0438\u0435 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438: <code>const namespaceYou = new function(){...} - <\/code>\u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f namespace, \u0430 \u043d\u0435 \u0447\u0443\u0434\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439.<\/p>\n<p>\u0415\u0441\u0442\u044c \u0438 \u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u043d\u0435 \u0437\u0430\u0441\u043e\u0440\u044f\u0442\u044c \u043e\u0431\u0449\u0435\u0435 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u043e \u043a\u043e\u0434\u043e\u043c (\u043d\u0435\u043a\u043e\u0442\u043e\u0440\u0430\u044f \u044d\u043a\u043e\u043b\u043e\u0433\u0438\u0447\u043d\u043e\u0441\u0442\u044c \u0442\u0430\u043a \u0441\u043a\u0430\u0437\u0430\u0442\u044c) &#8212; \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u0437\u044f\u0442\u044c \u0432\u0430\u0448 \u043a\u043e\u0434 \u0432 \u0444\u0438\u0433\u0443\u0440\u043d\u044b\u0435 \u0441\u043a\u043e\u0431\u043a\u0438 { } \u0438 \u043d\u0435 \u0437\u043b\u043e\u0443\u043f\u043e\u0442\u0440\u0435\u0431\u043b\u044f\u0442\u044c \u043c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0430\u043c\u0438 var \u0438 function:<\/p>\n<pre><code class=\"javascript\">{ \/\/namespace1     class Simple {         constructor() {             console.log(\"Simple created\");         }         print() {             console.log(\"Simple called\");         }     }      let simple = new Simple();      \/\/\u044d\u043a\u0441\u043f\u043e\u0440\u0442      var namespace1 = {simpleObject: simple, SimpleClass: Simple}; }  {\/\/namespace2     namespace1.simpleObject.print();     let simple = new namespace1.SimpleClass(); }<\/code><\/pre>\n<p>\u041a\u0440\u0430\u0441\u043e\u0442\u0430.<\/p>\n<p>\u041a\u043e\u0433\u0434\u0430 \u043d\u0438\u0431\u0443\u0434\u044c \u0432\u0435\u0431-workers \u043d\u0430\u0447\u043d\u0443\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u043c\u043e\u0434\u0443\u043b\u044f\u043c\u0438, \u0430 CORS policy \u0440\u0430\u0437\u0440\u0435\u0448\u0438\u0442 \u043f\u0438\u0441\u0430\u0442\u044c \u0432\u0430\u043c \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0435 \u043c\u043e\u0434\u0443\u043b\u044c\u043d\u044b\u0435 js-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0438 \u0432\u0441\u0435 \u044d\u0442\u043e \u0443\u0439\u0434\u0451\u0442 \u0432 \u0438\u0441\u0442\u043e\u0440\u0438\u044e. \u041a\u043e\u0433\u0434\u0430-\u043d\u0438\u0431\u0443\u0434\u044c &#8230;<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/583130\/\"> https:\/\/habr.com\/ru\/articles\/583130\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-415671","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/415671","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=415671"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/415671\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=415671"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=415671"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=415671"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}