{"id":210596,"date":"2014-01-28T13:45:03","date_gmt":"2014-01-28T09:45:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=210596"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=210596","title":{"rendered":"<span class=\"post_title\">\u041f\u0430\u0442\u0442\u0435\u0440\u043d JavaScript \u043f\u0441\u0435\u0432\u0434\u043e-\u043a\u043b\u0430\u0441\u0441 (pseudo-classical)<\/span>"},"content":{"rendered":"<div class=\"content html_format\">       \u0412 \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0435, \u043e\u0431\u044a\u0435\u043a\u0442 \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0435, \u0430 \u0435\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u044b \u043e\u0431\u044a\u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0432 \u043f\u0440\u043e\u0442\u043e\u0442\u0438\u043f\u0435.<\/p>\n<p>  \u0414\u0430\u043d\u043d\u044b\u0439 \u043f\u0430\u0442\u0442\u0435\u0440\u043d \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432\u043e \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430\u0445, \u0442\u0430\u043a\u0438\u0445 \u043a\u0430\u043a Google Closure Library. \u041d\u0430\u0442\u0438\u0432\u043d\u044b\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b JavaScript \u0442\u0430\u043a\u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u0434\u0430\u043d\u043d\u044b\u0439 \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0442.<\/p>\n<h4>\u041e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u0435 Pseudo-class<\/h4>\n<p>  \u0422\u0435\u0440\u043c\u0438\u0442 Pseudo-class \u0432\u044b\u0431\u0440\u0430\u043d \u043f\u043e\u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u0432 JavaScript \u043d\u0435\u0442 \u043a\u0430\u043a \u0442\u0430\u043a\u043e\u0432\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432, \u043a\u0430\u043a \u0432 \u0434\u0440\u0443\u0433\u0438\u0445 \u044f\u0437\u044b\u043a\u0430 \u043a\u0430\u043a C, Java, PHP \u0438 \u0434\u0440., \u043d\u043e \u0434\u0430\u043d\u043d\u044b\u0439 \u043f\u0430\u0442\u0442\u0435\u0440\u043d \u0431\u043b\u0438\u0437\u043e\u043a \u043a \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044e \u043a\u043b\u0430\u0441\u0441\u0430.<a name=\"habracut\"><\/a><\/p>\n<p>  \u041f\u0441\u0435\u0432\u0434\u043e-\u043a\u043b\u0430\u0441\u0441 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430 \u0438 \u043c\u0435\u0442\u043e\u0434\u043e\u0432.<\/p>\n<p>  \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0441\u0435\u0432\u0434\u043e-\u043a\u043b\u0430\u0441\u0441 <code>Animal<\/code> \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0437\u0430 \u043e\u0434\u043d\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 <code>sit<\/code> \u0438 2 \u0441\u0432\u043e\u0439\u0441\u0442\u0432:<\/p>\n<pre><code class=\"javascript\">function Animal(name) {   this.name = name }  Animal.prototype = {    canWalk: true,   sit: function() {     this.canWalk = false     alert(this.name + ' sits down.')   } }  var animal = new Animal('Pet') \/\/ (1)  alert(animal.canWalk) \/\/ true  animal.sit()             \/\/ (2)  alert(animal.canWalk) \/\/ false <\/code><\/pre>\n<p>  <\/p>\n<ol>\n<li>\u041a\u043e\u0433\u0434\u0430 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f <code>new Animal(name)<\/code>, \u043e\u0431\u044a\u0435\u043a\u0442 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u0441\u0441\u044b\u043b\u043a\u0443 <code>__proto__<\/code> \u043d\u0430 <code>Animal.prototype<\/code> (\u0441\u043c. \u043f\u0440\u0430\u0432\u0443\u044e \u0447\u0430\u0441\u0442\u044c \u0441\u0445\u0435\u043c\u044b).<\/li>\n<li>\u041c\u0435\u0442\u043e\u0434 <code>animal.sit<\/code> \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u0442 <code>animal.canWalk<\/code> \u0432 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0435, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0430\u0448\u0435 \u0436\u0438\u0432\u043e\u0442\u043d\u043e\u0435 \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0445\u043e\u0434\u0438\u0442\u044c, \u0430 \u0434\u0440\u0443\u0433\u0438\u0435 \u043c\u043e\u0433\u0443\u0442.<\/li>\n<\/ol>\n<p>  <img decoding=\"async\" src=\"http:\/\/habr.habrastorage.org\/post_images\/8ee\/199\/8c7\/8ee1998c7e87db8435c511e2d4067386.png\" alt=\"image\"\/>  <\/p>\n<h5>\u0421\u0445\u0435\u043c\u0430 \u043f\u0441\u0435\u0432\u0434\u043e-\u043a\u043b\u0430\u0441\u0441\u0430:<\/h5>\n<p>  <\/p>\n<ol>\n<li>\u041c\u0435\u0442\u043e\u0434\u044b \u0438 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0442\u0441\u044f \u0432 \u043f\u0440\u043e\u0442\u043e\u0442\u0438\u043f\u0435.<\/li>\n<li>\u041c\u0435\u0442\u043e\u0434\u044b \u0432 <code>prototype<\/code> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 <code>this<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043d\u0430 \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u0442\u0430\u043a \u043a\u0430\u043a \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <code>this<\/code> \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 \u0432\u044b\u0437\u043e\u0432\u0430. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432 <code>animal.sit()<\/code> <code>this<\/code> \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u044c\u0441\u044f \u043a <code>animal<\/code>.<\/li>\n<\/ol>\n<p>  <\/p>\n<h4>\u041d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435<\/h4>\n<p>  \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043d\u043e\u0432\u044b\u0439 \u043a\u043b\u0430\u0441\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043e\u0442 <code>Animal<\/code>, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 <code>Rabbit<\/code>:<\/p>\n<pre><code class=\"javascript\">function Rabbit(name) {   this.name = name }  Rabbit.prototype.jump = function() {   this.canWalk = true   alert(this.name + ' jumps!') }  var rabbit = new Rabbit('John') <\/code><\/pre>\n<p>  \u041a\u0430\u043a \u0432\u0438\u0434\u0438\u043c, \u043a\u0440\u043e\u043b\u0438\u043a \u0438\u043c\u0435\u0435\u0442 \u0442\u0430\u043a\u0443\u044e \u0436\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u043a\u0430\u043a \u0438 <code>Animal<\/code> \u2014 \u043c\u0435\u0442\u043e\u0434 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d \u0432 \u043f\u0440\u043e\u0442\u043e\u0442\u0438\u043f\u0435.<\/p>\n<p>  \u0414\u043b\u044f \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044f \u043e\u0442 <code>Animal<\/code>, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a <code>Rabbit.prototype.__proto__ == Animal.prototype<\/code>. \u042d\u0442\u043e \u0435\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u0435, \u0442\u0430\u043a \u043a\u0430\u043a \u0435\u0441\u043b\u0438 \u043c\u0435\u0442\u043e\u0434 \u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u043d \u0432 <code> Rabbit.prototype<\/code>, \u0442\u043e \u0435\u0433\u043e \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043a\u0430\u0442\u044c \u0432 \u043c\u0435\u0442\u043e\u0434\u0430\u0445 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044f <code>Animal.prototype<\/code>.<\/p>\n<p>  \u0412\u043e\u0442 \u0442\u0430\u043a, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habr.habrastorage.org\/post_images\/865\/a8a\/e94\/865a8ae94b75f407663c9b288adaa43e.png\" alt=\"image\"\/><\/p>\n<p>  \u0427\u0442\u043e\u0431\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e, \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u0443\u0441\u0442\u043e\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 <code>Rabbit.prototype<\/code> \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u043c\u044b \u043e\u0442 <code>Animal.prototype<\/code> \u0438 \u043f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043c\u0435\u0442\u043e\u0434\u044b.<\/p>\n<pre><code class=\"javascript\">function Rabbit(name) {   this.name = name }  Rabbit.prototype = inherit(Animal.prototype)  Rabbit.prototype.jump = function() { ... } <\/code><\/pre>\n<p>  \u0413\u0434\u0435 <code>inherit<\/code> \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u043f\u0443\u0441\u0442\u043e\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u0441 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u043c <code>__proto__<\/code>:<\/p>\n<pre><code class=\"javascript\">function inherit(proto) {   function F() {}   F.prototype = proto   return new F } <\/code><\/pre>\n<p>  \u0412\u043e\u0442 \u0447\u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u0432 \u043a\u043e\u043d\u0446\u0435:<\/p>\n<pre><code class=\"javascript\">\/\/ Animal  function Animal(name) {   this.name = name }  \/\/ Animal methods Animal.prototype = {    canWalk: true,   sit: function() {     this.canWalk = false     alert(this.name + ' sits down.')   } }  \/\/ Rabbit function Rabbit(name) {   this.name = name }  \/\/ inherit Rabbit.prototype = inherit(Animal.prototype)  \/\/ Rabbit methods Rabbit.prototype.jump = function() {   this.canWalk = true   alert(this.name + ' jumps!') }  \/\/ Usage var rabbit = new Rabbit('Sniffer')  rabbit.sit()   \/\/ Sniffer sits. rabbit.jump()  \/\/ Sniffer jumps! <\/code><\/pre>\n<p>  <\/p>\n<h4>\u041d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 <code>new Animal<\/code> \u0434\u043b\u044f \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044f<\/h4>\n<p>  \u0425\u043e\u0440\u043e\u0448\u043e \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0439, \u043d\u043e \u043d\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044f, \u044d\u0442\u043e \u043a\u043e\u0433\u0434\u0430 \u0432\u043c\u0435\u0441\u0442\u043e <code>Rabbit.prototype = inherit(Animal.prototype)<\/code> \u043b\u044e\u0434\u0438 \u0434\u0435\u043b\u0430\u044e\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/p>\n<pre><code class=\"javascript\">\/\/ inherit from Animal Rabbit.prototype = new Animal() <\/code><\/pre>\n<p>  \u041a\u0430\u043a \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442, \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c <code>new Animal<\/code> \u0432 \u043f\u0440\u043e\u0442\u043e\u0442\u0438\u043f\u0435. \u041d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u0442\u0430\u043a \u043a\u0430\u043a <code>new Animal<\/code> \u0435\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u0442 <code>Animal.prototype<\/code>.<\/p>\n<p>  \u2026 \u041d\u043e \u043a\u0442\u043e \u0441\u043a\u0430\u0437\u0430\u043b, \u0447\u0442\u043e <code>new Animal()<\/code> \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0432\u044b\u0437\u0432\u0430\u043d \u0431\u0435\u0437 <code>name<\/code>? \u041a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u043c\u043e\u0436\u0435\u0442 \u0441\u0442\u0440\u043e\u0433\u043e \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u0442\u044c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0438 \u0443\u043c\u0435\u0440\u0435\u0442\u044c \u0431\u0435\u0437 \u043d\u0438\u0445.<\/p>\n<p>  \u041d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435, \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0435 \u0431\u043e\u043b\u0435\u0435 \u043a\u043e\u043d\u0446\u0435\u043f\u0442\u0443\u0430\u043b\u044c\u043d\u0430\u044f \u0447\u0435\u043c \u044d\u0442\u0430. \u041c\u044b \u043d\u0435 \u0445\u043e\u0442\u0438\u043c \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c <code>Animal<\/code>. \u041c\u044b \u0432\u0441\u0435\u0433\u043e \u043b\u0438\u0448\u044c \u0445\u043e\u0442\u0438\u043c \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c \u043e\u0442 \u043d\u0435\u0433\u043e.<\/p>\n<p>  \u0412\u043e\u0442 \u043f\u043e\u0447\u0435\u043c\u0443 <code>Rabbit.prototype = inherit(Animal.prototype)<\/code> \u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0442\u0438\u0442\u0435\u043b\u0435\u043d. \u0410\u043a\u043a\u0443\u0440\u0430\u0442\u043d\u044b\u0439 \u043d\u0430\u0441\u043b\u0435\u0434\u0441\u0442\u0432\u043e \u0431\u0435\u0437 \u043f\u043e\u0431\u043e\u0447\u043d\u044b\u0445 \u044d\u0444\u0444\u0435\u043a\u0442\u043e\u0432.<\/p>\n<h4>\u0412\u044b\u0437\u043e\u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430 \u0441\u0443\u043f\u0435\u0440\u043a\u043b\u0430\u0441\u0441\u0430<\/h4>\n<p>  \u041a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0441\u0443\u043f\u0435\u0440\u043a\u043b\u0430\u0441\u0441\u0430 \u0442\u0435\u043f\u0435\u0440\u044c \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438. \u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u0440\u0443\u0447\u043a\u0430\u043c\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>Animal.apply()<\/code> \u0434\u043b\u044f \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430:<\/p>\n<pre><code class=\"javascript\">function Rabbit(name) {   Animal.apply(this, arguments) } <\/code><\/pre>\n<p>  \u0414\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 <code>Animal<\/code> \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0438 \u043e\u043d \u0437\u0430\u0434\u0430\u0435\u0442 <code>name<\/code> \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430.<\/p>\n<h4>\u041f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 (\u043f\u043e\u043b\u0438\u043c\u043e\u0440\u0444\u0438\u0437\u043c)<\/h4>\n<p>  \u0427\u0442\u043e\u0431\u044b \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 \u043c\u0435\u0442\u043e\u0434, \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u0435 \u0435\u0433\u043e \u0432 \u0434\u043e\u0447\u0435\u0440\u043d\u0435\u043c \u043f\u0440\u043e\u0442\u043e\u0442\u0438\u043f\u0435:<\/p>\n<pre><code class=\"javascript\">Rabbit.prototype.sit = function() {   alert(this.name + ' sits in a rabbity way.') } <\/code><\/pre>\n<p>  \u041f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 <code>rabbit.sit()<\/code> <code>sit<\/code> \u0438\u0449\u0435\u0442\u0441\u044f \u043f\u043e \u0446\u0435\u043f\u043e\u0447\u043a\u0435 <code>rabbit -&gt; Rabbit.prototype -&gt; Animal.prototype<\/code> \u0438 \u043d\u0430\u0445\u043e\u0434\u0438\u0442 \u0435\u0433\u043e \u0432 <code>Rabbit.prototype<\/code> \u043d\u0435 \u0434\u043e\u0445\u043e\u0434\u044f \u0434\u043e <code>Animal.prototype<\/code>.<\/p>\n<p>  \u041a\u043e\u043d\u0435\u0447\u043d\u043e, \u043c\u044b \u043c\u043e\u0436\u0435\u0442 \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0435\u0433\u043e \u0438\u043d\u0430\u0447\u0435 \u2014 \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0432 \u043e\u0431\u044a\u0435\u043a\u0442\u0435:<\/p>\n<pre><code class=\"javascript\">rabbit.sit = function() {   alert('A special sit of this very rabbit ' + this.name) } <\/code><\/pre>\n<p>  <\/p>\n<h5>\u0412\u044b\u0437\u043e\u0432 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 \u043f\u043e\u0441\u043b\u0435 \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f<\/h5>\n<p>  \u041f\u043e\u0441\u043b\u0435 \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043c\u0435\u0442\u043e\u0434\u0430, \u043d\u0430\u043c \u043f\u043e-\u043f\u0440\u0435\u0436\u043d\u0435\u043c\u0443 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044f. \u042d\u0442\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0435\u0441\u043b\u0438 \u043c\u044b \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u043e\u0431\u0440\u0430\u0442\u0438\u043c\u0441\u044f \u043a \u043f\u0440\u043e\u0442\u043e\u0442\u0438\u043f\u0443 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044f.<\/p>\n<pre><code class=\"javascript\">Rabbit.prototype.sit = function() {   alert('calling superclass sit:')   Animal.prototype.sit.apply(this, arguments) } <\/code><\/pre>\n<p>  \u0412\u0441\u0435 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>apply\/call<\/code> \u043a\u0443\u0434\u0430 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442\u0441\u044f \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u043a\u0430\u043a <code>this<\/code>. \u041f\u0440\u043e\u0441\u0442\u043e\u0439 \u0432\u044b\u0437\u043e\u0432 <code>Animal.prototype.sit()<\/code> \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>Animal.prototype<\/code> \u043a\u0430\u043a <code>this<\/code>.<\/p>\n<h5>Sugar: removing direct reference to parent<\/h5>\n<p>  \u0412 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435, \u043c\u044b \u0432\u044b\u0437\u044b\u0432\u0430\u043b\u0438 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 \u043a\u043b\u0430\u0441\u0441 \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e. \u041a\u0430\u043a \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440: <code>Animal.apply...<\/code>, \u0438\u043b\u0438 \u043c\u0435\u0442\u043e\u0434: <code>Animal.prototype.sit.apply...<\/code>.<\/p>\n<p>  \u041d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435, \u043c\u044b \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e\u0433\u043e. \u041f\u0440\u0438 \u0440\u0435\u0444\u0440\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u043e \u0438\u043c\u044f \u043b\u0438\u0431\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043e\u0447\u043d\u044b\u0445 \u043a\u043b\u0430\u0441\u0441 \u0432 \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0438.<\/p>\n<p>  \u041e\u0431\u044b\u0447\u043d\u043e, \u044f\u0437\u044b\u043a\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u0445 \u0441\u043b\u043e\u0432, \u043a\u0430\u043a, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <code>parent.method()<\/code> \u0438\u043b\u0438 <code>super()<\/code>.<\/p>\n<p>  \u041d\u043e \u0432 JavaScript \u0442\u0430\u043a\u043e\u0433\u043e \u043d\u0435\u0442, \u043d\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u0442 \u0441\u043c\u043e\u0434\u0435\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e.<\/p>\n<p>  \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0435\u0442 \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435 \u0438 \u0442\u0430\u043a\u0436\u0435 \u0437\u0430\u0434\u0430\u0435\u0442 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044f \u0438 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0431\u0435\u0437 \u043f\u0440\u044f\u043c\u043e\u0439 \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u043d\u0435\u0433\u043e:<\/p>\n<pre><code class=\"javascript\">function extend(Child, Parent) {   Child.prototype = inherit(Parent.prototype)   Child.prototype.constructor = Child   Child.parent = Parent.prototype } <\/code><\/pre>\n<p>  \u0412\u043e\u0442 \u0442\u0430\u043a \u0432\u043e\u0442 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c:<\/p>\n<pre><code class=\"javascript\">function Rabbit(name) {   Rabbit.parent.constructor.apply(this, arguments) \/\/ super constructor }  extend(Rabbit, Animal)  Rabbit.prototype.run = function() {     Rabbit.parent.run.apply(this, arguments) \/\/ parent method     alert(&quot;fast&quot;) } <\/code><\/pre>\n<p>  \u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0435\u0440\u0435\u0438\u043c\u0435\u043d\u043e\u0432\u0430\u0442\u044c <code>Animal<\/code> \u0438\u043b\u0438 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043e\u0447\u043d\u044b\u0445 \u043a\u043b\u0430\u0441\u0441 <code>GrassEatingAnimal<\/code> \u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u0442\u0440\u043e\u043d\u0443\u0442 \u0442\u043e\u043b\u044c\u043a\u043e <code>Animal<\/code> \u0438 <code>extend(...)<\/code>.<\/p>\n<h4>\u041f\u0440\u0438\u0432\u0430\u0442\u043d\u044b\u0435 \u0438 \u0437\u0430\u0449\u0438\u0449\u0435\u043d\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b (\u0438\u043d\u043a\u0430\u043f\u0441\u0443\u043b\u044f\u0446\u0438\u044f)<\/h4>\n<p>  \u0417\u0430\u0449\u0438\u0449\u0451\u043d\u043d\u044b\u0435 (protected) \u043c\u0435\u0442\u043e\u0434\u044b \u0438 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u0441 \u0434\u043e\u0433\u043e\u0432\u043e\u0440\u0435\u043d\u043d\u043e\u0441\u0442\u044c\u044e \u043e\u0431 \u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u0438\u0435. \u041c\u0435\u0442\u043e\u0434\u044b, \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0438\u0435\u0441\u044f \u0441 \u043f\u043e\u0434\u0447\u0435\u0440\u043a\u0438\u0432\u0430\u043d\u0438\u044f &#8216;_&#8217;, \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0432\u044b\u0437\u0432\u0430\u0442\u044c\u0441\u044f \u0438\u0437 \u0432\u043d\u0435 (\u043d\u0430 \u0434\u0435\u043b\u0435 \u043c\u043e\u0433\u0443\u0442).<\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habr.habrastorage.org\/post_images\/682\/c9a\/8ad\/682c9a8adf5e6b1e8f4429c2e2c44a25.png\" alt=\"image\"\/><\/p>\n<p>  \u041f\u0440\u0438\u0432\u0430\u0442\u043d\u044b\u0435 (private) \u043c\u0435\u0442\u043e\u0434\u044b \u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e\u0442\u0441\u044f.<\/p>\n<h4>\u0421\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 (static) \u043c\u0435\u0442\u043e\u0434\u044b \u0438 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430<\/h4>\n<p>  \u0421\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0438 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0442\u0441\u044f \u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0435:<\/p>\n<pre><code class=\"javascript\">function Animal() {    Animal.count++ } Animal.count = 0  new Animal() new Animal()  alert(Animal.count) \/\/ 2 <\/code><\/pre>\n<p>  <\/p>\n<h4>\u0418\u0442\u043e\u0433\u043e<\/h4>\n<p>  \u0412\u043e\u0442 \u0438 \u043d\u0430\u0448 \u0441\u0443\u043f\u0435\u0440-\u043c\u0435\u0433\u0430-\u041e\u041e\u041f \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a:<\/p>\n<pre><code class=\"javascript\">function extend(Child, Parent) {   Child.prototype = inherit(Parent.prototype)   Child.prototype.constructor = Child   Child.parent = Parent.prototype } function inherit(proto) {   function F() {}   F.prototype = proto   return new F } <\/code><\/pre>\n<p>  \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435:<\/p>\n<pre><code class=\"javascript\">\/\/ --------- the base object ------------ function Animal(name) {   this.name = name }  \/\/ methods Animal.prototype.run = function() {   alert(this + &quot; is running!&quot;) }  Animal.prototype.toString = function() {   return this.name }   \/\/ --------- the child object ----------- function Rabbit(name) {   Rabbit.parent.constructor.apply(this, arguments) }  \/\/ inherit extend(Rabbit, Animal)  \/\/ override Rabbit.prototype.run = function() {   Rabbit.parent.run.apply(this)   alert(this + &quot; bounces high into the sky!&quot;) }  var rabbit = new Rabbit('Jumper') rabbit.run() <\/code><\/pre>\n<p>  \u0412 \u043d\u0430\u0448 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0447\u0443\u0442\u043e\u043a \u0441\u0430\u0445\u0430\u0440\u043a\u0443, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043a\u043e\u043f\u0438\u0440\u0443\u044e \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u0438\u0437 \u043e\u0434\u043d\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0432 \u0434\u0440\u0443\u0433\u043e\u0439:<\/p>\n<pre><code class=\"javascript\">mixin(Animal.prototype, { run: ..., toString: ...}) <\/code><\/pre>\n<p>  \u041d\u043e \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u0432\u0430\u043c \u043d\u0435 \u043e\u0447\u0435\u043d\u044c-\u0442\u043e \u0438 \u043d\u0443\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u041e\u041e\u041f \u043f\u0430\u0442\u0442\u0435\u0440\u043d. \u0412\u0441\u0435\u0433\u043e \u043b\u0438\u0448\u044c \u0434\u0432\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0441\u043f\u0440\u0430\u0432\u044f\u0442\u0441\u044f \u0441 \u044d\u0442\u0438\u043c.   \t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/210596\/\"> http:\/\/habrahabr.ru\/post\/210596\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">       \u0412 \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0435, \u043e\u0431\u044a\u0435\u043a\u0442 \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0435, \u0430 \u0435\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u044b \u043e\u0431\u044a\u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0432 \u043f\u0440\u043e\u0442\u043e\u0442\u0438\u043f\u0435.<\/p>\n<p>  \u0414\u0430\u043d\u043d\u044b\u0439 \u043f\u0430\u0442\u0442\u0435\u0440\u043d \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432\u043e \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430\u0445, \u0442\u0430\u043a\u0438\u0445 \u043a\u0430\u043a Google Closure Library. \u041d\u0430\u0442\u0438\u0432\u043d\u044b\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b JavaScript \u0442\u0430\u043a\u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u0434\u0430\u043d\u043d\u044b\u0439 \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0442.<\/p>\n<h4>\u041e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u0435 Pseudo-class<\/h4>\n<p>  \u0422\u0435\u0440\u043c\u0438\u0442 Pseudo-class \u0432\u044b\u0431\u0440\u0430\u043d \u043f\u043e\u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u0432 JavaScript \u043d\u0435\u0442 \u043a\u0430\u043a \u0442\u0430\u043a\u043e\u0432\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432, \u043a\u0430\u043a \u0432 \u0434\u0440\u0443\u0433\u0438\u0445 \u044f\u0437\u044b\u043a\u0430 \u043a\u0430\u043a C, Java, PHP \u0438 \u0434\u0440., \u043d\u043e \u0434\u0430\u043d\u043d\u044b\u0439 \u043f\u0430\u0442\u0442\u0435\u0440\u043d \u0431\u043b\u0438\u0437\u043e\u043a \u043a \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044e \u043a\u043b\u0430\u0441\u0441\u0430.<\/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-210596","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/210596","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=210596"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/210596\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=210596"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=210596"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=210596"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}