{"id":264686,"date":"2015-09-01T11:07:02","date_gmt":"2015-09-01T07:07:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=264686"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=264686","title":{"rendered":"\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 ES6 \u0432 AngularJs 1.x \u0441\u043e \u0441\u0431\u043e\u0440\u043a\u043e\u0439 Browserify+Babel"},"content":{"rendered":"<p>             \u0412 \u0441\u0442\u0430\u0442\u044c\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043a\u0430\u043a \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043d\u0430 ES6 \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u0435 \u0447\u0430\u0441\u0442\u0438 AngularJs \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0437\u0430\u0442\u0435\u043c \u0441\u043e\u0431\u0440\u0430\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Browserify \u0438 Babel \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0441\u043a\u0430\u0447\u0430\u0442\u044c \u0441 <a href=\"https:\/\/github.com\/SRobertZ\/es6angular\">github<\/a> \u0438 \u043f\u043e\u0438\u0433\u0440\u0430\u0442\u044c\u0441\u044f.<br \/>  <a name=\"habracut\"><\/a><br \/>  <b>\u041f\u0438\u0448\u0435\u043c Controller<\/b><\/p>\n<p>  \u041a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u0432 AngularJs \u044d\u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f-\u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043c\u043e\u0436\u0435\u0442 \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0442\u044c \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0435\u043c\u044b\u0439 scope \u043b\u0438\u0431\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0438\u043d\u0436\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 $scope \u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430, \u043b\u0438\u0431\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u043e\u0434\u0445\u043e\u0434\u0430 \u00abcontroller as\u00bb. \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0431\u043e\u043b\u0435\u0435 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u0447\u0435\u0440\u0435\u0437 \u0438\u043d\u0436\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 $scope \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438:  <\/p>\n<pre><code class=\"javascript\">class SignupController {     constructor($scope, $state, accountService) {         this.init($scope, $state, accountService);     }     init($scope, $state, accountService) {         $scope.signup = function () {             accountService.signup().then(()=&gt; {                 $state.go('main.list');             });         };     } } SignupController.$inject = ['$scope', '$state', 'accountService']; export {SignupController} <\/code><\/pre>\n<p>  \u041a\u0430\u043a \u0432\u0438\u0434\u043d\u043e \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d ES6 \u043a\u043b\u0430\u0441\u0441\u043e\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u043d\u0436\u0435\u043a\u0442\u0438\u0440\u0443\u0435\u0442 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 $scope \u0438 \u0434\u0432\u0443\u0445 \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432 \u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440.<\/p>\n<p>  \u0417\u0434\u0435\u0441\u044c \u0445\u043e\u0447\u0443 \u0441\u0440\u0430\u0437\u0443 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u043c\u044b \u043f\u043e\u0442\u0435\u0440\u044f\u043b\u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u044f\u0442\u044c \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f inline array annotation, \u0442\u043e \u0435\u0441\u0442\u044c \u0442\u0430\u043a:   <\/p>\n<pre><code class=\"javascript\">someModule.controller('MyController', ['$scope', 'greeter', function($scope, greeter) {   \/\/ ... }]);  <\/code><\/pre>\n<p>  \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u044f \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439 \u0438 \u0438\u0445 \u043f\u043e\u0440\u044f\u0434\u043a\u0430 \u0438\u043d\u0436\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0435\u0440\u0435\u0437 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e $inject, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c\u043e\u0435 \u0432 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u043e\u043c \u043a\u043b\u0430\u0441\u0441\u0435 SignupController.<\/p>\n<p>  \u0412\u0442\u043e\u0440\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043f\u043e\u0434\u0445\u043e\u0434\u0430 \u00abcontroller as\u00bb \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0431\u043e\u043b\u0435\u0435 \u00ab\u0432\u043e\u043b\u0448\u0435\u0431\u043d\u044b\u043c\u00bb \u0432 \u0441\u043e\u0447\u0435\u0442\u0430\u043d\u0438\u0438 \u0441 ES6 \u043a\u043b\u0430\u0441\u0441\u043e\u043c. \u0418 \u043f\u0440\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0438 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430 \u044f \u0441\u0447\u0438\u0442\u0430\u044e \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0442\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c.<\/p>\n<pre><code class=\"javascript\">var _state = new WeakMap(); var _accountService = new WeakMap();  class SigninController {     constructor($state, accountService) {         _state.set(this, $state);         _accountService.set(this, accountService);     }     login() {         _accountService.get(this).login().then(()=&gt; {             _state.get(this).go('main.list');         });     }; } SigninController.$inject = ['$state', 'accountService']; export {SigninController} <\/code><\/pre>\n<p>  \u041a\u0430\u043a \u0432\u0438\u0434\u043d\u043e \u043a\u043b\u0430\u0441\u0441 \u0443\u0442\u0440\u0430\u0442\u0438\u043b \u044f\u0432\u043d\u043e\u0435 \u0443\u043f\u043e\u043c\u0438\u043d\u0430\u043d\u0438\u0435 scope, \u0441\u0442\u0430\u043b \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0431\u043e\u043b\u0435\u0435 \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b\u043c \u043e\u0442 AngularJs \u0438 \u0434\u0430\u0436\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u0438\u043d\u0436\u0435\u043a\u0442\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440. \u041d\u043e \u0442\u0435\u043f\u0435\u0440\u044c \u0432 \u043a\u043b\u0430\u0441\u0441\u0435 \u043f\u043e\u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043f\u0440\u0438\u0432\u0430\u0442\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0438 \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u043d\u0438\u043c\u0438 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0438\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u043a\u043b\u0430\u0441\u0441\u0430. \u041e\u0447\u0435\u043d\u044c \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e \u043e\u0431 \u044d\u0442\u043e\u043c \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043e \u0432 \u0441\u0442\u0430\u0442\u044c\u0435 &quot;<a href=\"http:\/\/habrahabr.ru\/post\/257305\/\">\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u0440\u0438\u0432\u0430\u0442\u043d\u044b\u0445 \u043f\u043e\u043b\u0435\u0439 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e WeakMap \u0432 JavaScript<\/a>&quot; \u0438 \u043b\u0443\u0447\u0448\u0438\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u0435\u043c \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u044e\u0449\u0438\u043c \u043e\u0441\u0432\u043e\u0431\u043e\u0436\u0434\u0435\u043d\u0438\u0435 \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432 \u0438 \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u0430\u043d\u043d\u043e\u043c\u0443 \u043a\u043b\u0430\u0441\u0441\u0443 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 WeakMap- \u0438\u0437 \u043c\u0438\u043d\u0443\u0441\u043e\u0432 \u2014 \u043f\u0438\u0448\u0435\u043c \u0447\u0443\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435 \u043a\u043e\u0434\u0430- \u043f\u043b\u044e\u0441\u044b- \u0441\u043f\u0438\u043c \u0441\u043f\u043e\u043a\u043e\u0439\u043d\u043e.<\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0448\u0430\u0433- \u043e\u0431\u044a\u044f\u0432\u0438\u0442\u044c Controller \u0432 \u043c\u043e\u0434\u0443\u043b\u0435 Angular.<\/p>\n<p>  \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u044f \u0441\u043e\u0437\u0434\u0430\u043b \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u0444\u0430\u0439\u043b module.js, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 ES6 \u043c\u043e\u0434\u0443\u043b\u0435\u0439 \u0438 \u0438\u0445 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u0432 \u043c\u043e\u0434\u0443\u043b\u044f\u0445 Angular.<\/p>\n<pre><code class=\"javascript\">import router from '.\/router.js'; import {SigninController} from '.\/controllers\/signin\/signin.controller.js';   angular.module('account').controller('SigninController', SigninController); <\/code><\/pre>\n<p>  <b>\u041f\u0438\u0448\u0435\u043c Provider, Factory, Service<\/b><\/p>\n<p>  \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u0448\u0430\u0433\u043e\u043c \u0431\u0443\u0434\u0435\u0442 \u0432\u043d\u0435\u0434\u0440\u0435\u043d\u0438\u0435 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u0431\u0438\u0437\u043d\u0435\u0441 \u043b\u043e\u0433\u0438\u043a\u0438- \u0432 \u043c\u043e\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043a\u043b\u0430\u0441\u0441 AccountService.<\/p>\n<p>  \u0412\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043e\u043d \u0442\u0430\u043a\u0436\u0435 \u0432\u043e\u043b\u0448\u0435\u0431\u043d\u043e \u043a\u0430\u043a \u0438 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0439 \u043a\u043b\u0430\u0441\u0441- \u0431\u0435\u0437\u043e \u0432\u0441\u044f\u043a\u0438\u0445 \u0443\u043f\u043e\u043c\u0438\u043d\u0430\u043d\u0438\u0439 \u043e\u0431 AngularJs<\/p>\n<pre><code class=\"javascript\">import api from '.\/accountApi.factory.js';  class AccountService {     login(){         return api.login();     }     signup(){         return api.signup();     } } export {AccountService} <\/code><\/pre>\n<p>  \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u043a\u043b\u0430\u0441\u0441 AccountService \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u043c\u043e\u0434\u0443\u043b\u044f, \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u043d\u043e\u043c \u0432 \u0444\u0430\u0439\u043b\u0435 accountApi.factory.js, \u043d\u043e \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0430, \u0430 \u043d\u0435 \u0438\u043d\u0436\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u0430 DI \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c\u044b\u043c AngularJs. \u0412 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435 \u0438 \u0432 \u0432\u044b\u0448\u0435\u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 AccountService \u043c\u043e\u0433 \u0431\u044b\u0442\u044c \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d, \u0430 \u043d\u0435 \u0438\u043d\u0436\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d. \u0412\u0441\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u0442\u043e\u0433\u043e \u043a\u0430\u043a \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0441\u0432\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435.<\/p>\n<p>  \u0418\u0442\u0430\u043a \u043a\u043b\u0430\u0441\u0441 \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u043e\u043f\u0438\u0441\u0430\u043d, \u0442\u0435\u043f\u0435\u0440\u044c \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u043e\u0431\u044a\u044f\u0432\u0438\u0442\u044c \u0441\u0435\u0440\u0432\u0438\u0441 \u0432 \u043c\u043e\u0434\u0443\u043b\u0435 Angular.<\/p>\n<p>  \u0421\u0435\u0440\u0432\u0438\u0441 Angular&#8217;\u0430 \u043e\u0431\u044a\u044f\u0432\u0438\u0442\u044c \u043f\u0440\u043e\u0449\u0435 \u0432\u0441\u0435\u0433\u043e. \u0421 Factory \u0438 Provider \u0432\u0441\u0435 \u043e\u0431\u0441\u0442\u043e\u0438\u0442 \u043d\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0442\u0440\u043e\u043a \u0441\u043b\u043e\u0436\u043d\u0435\u0435.<\/p>\n<p>  \u041e\u0431\u044a\u044f\u0432\u043b\u044f\u0435\u043c \u0441\u0435\u0440\u0432\u0438\u0441 \u0432 \u043d\u0430\u0448\u0435\u043c \u0444\u0430\u0439\u043b\u0435 module.js:<\/p>\n<pre><code class=\"javascript\">........ import {AccountService} from '.\/services\/accountService.factory.js'; ......... angular.module('account').service('accountService', AccountService); <\/code><\/pre>\n<p>  \u0417\u0434\u0435\u0441\u044c \u0432\u0441\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u2014 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u043d \u044d\u043a\u0437\u0435\u043c\u043b\u044f\u0440 \u043a\u043b\u0430\u0441\u0441\u0430 AccountService \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 new, \u0442\u0430\u043a \u043a\u0430\u043a \u043c\u0435\u0442\u043e\u0434 service \u043e\u0436\u0438\u0434\u0430\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440.<\/p>\n<p>  \u041a\u0430\u043a \u0431\u044b \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u043b \u043a\u043e\u0434, \u0435\u0441\u043b\u0438 \u0431\u044b \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u043e\u0431\u044a\u044f\u0432\u0438\u0442\u044c provider:<\/p>\n<pre><code class=\"javascript\">angular.module('account').provider('accountService', providerBuilder(AccountService));  function providerBuilder(obj) {     return function () {          this.$get = [function () {                return new obj();                }];              }            } <\/code><\/pre>\n<p>  \u0418 \u043d\u0430\u043a\u043e\u043d\u0435\u0446, \u0435\u0441\u043b\u0438 \u0431\u044b \u043d\u0430\u043c \u043d\u0443\u0436\u0435\u043d \u0431\u044b\u043b factory:<\/p>\n<pre><code class=\"javascript\">angular.module('account').factory('accountService', function(){return new AccountService()}); <\/code><\/pre>\n<p>  \u0410 \u043b\u0443\u0447\u0448\u0435 \u043e\u0431\u044a\u044f\u0432\u0438\u0442\u044c \u0432 \u043a\u043b\u0430\u0441\u0441\u0435 AccountService \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u043a\u043b\u0430\u0441\u0441\u0430 \u0438 \u0442\u043e\u0433\u0434\u0430 \u043a\u043e\u0434 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0442\u0430\u043a:<\/p>\n<pre><code class=\"javascript\">angular.module('account').factory('accountService', AccountService.createInstance); \t <\/code><\/pre>\n<p>  \u041f\u0440\u0438\u043c\u0435\u0440 \u0441 \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u043c \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435\u043c \u044f \u043f\u0440\u0438\u0432\u0435\u0434\u0443 \u043d\u0438\u0436\u0435.<\/p>\n<p>  <b>\u041f\u0438\u0448\u0435\u043c directive<\/b><\/p>\n<p>  \u0414\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u0430 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0442\u0430\u043a:  <\/p>\n<pre><code class=\"javascript\">var _accountService = new WeakMap();  class Copyright {     constructor($templateCache, accountService) {         _accountService.set(this, accountService);         this.restrict = 'E';         this.template = $templateCache.get('account\/directives\/copyright\/copyright.directive.html');         this.scope = {};         this.controller = ['$scope', function ($scope) {             $scope.copyright = function () {                 return 'Page \u00a9 - 2015';             };         }];     }     link(scope) {         scope.doSomething = function () {             \/\/\u043a\u0430\u043a\u043e\u0439-\u043d\u0438\u0431\u0443\u0434\u044c \u043a\u043e\u0434             var accountService= _accountService.get(Copyright.instance);             \/\/\u043a\u0430\u043a\u043e\u0439-\u043d\u0438\u0431\u0443\u0434\u044c \u043a\u043e\u0434         }     }     static createInstance($templateCache, accountService) {         Copyright.instance = new Copyright($templateCache, accountService);         return Copyright.instance;     } } Copyright.$inject = ['$templateCache', 'accountService']; export {Copyright} <\/code><\/pre>\n<p>  \u041c\u043e\u044f \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u0430 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0434\u0435\u043b\u0430\u0435\u0442, \u043d\u043e \u0438\u043c\u0435\u0435\u0442 \u0432\u0441\u0435 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u0447\u0430\u0441\u0442\u0438.<\/p>\n<p>  \u0412 \u043a\u043b\u0430\u0441\u0441\u0435 \u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e \u0432\u0441\u0435 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0435 \u043f\u043e\u043b\u044f \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b \u0438 \u0445\u043e\u0447\u0443 \u0437\u0430\u043e\u0441\u0442\u0440\u0438\u0442\u044c \u0432\u0430\u0448\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u0442\u043e\u043c \u043a\u0430\u043a \u043e\u0431\u044a\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u0430.<br \/>  \u0414\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u0430 \u043e\u0431\u044a\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432 \u043c\u043e\u0434\u0443\u043b\u0435 Angular \u043f\u043e\u0447\u0442\u0438 \u0442\u0430\u043a\u0436\u0435 \u043a\u0430\u043a \u0438 factory, \u043d\u043e \u0435\u0441\u0442\u044c \u043e\u0434\u043d\u043e \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u043e\u0442\u043b\u0438\u0447\u0438\u0435: this \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 constructor \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0432\u0435\u043d this \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 link \u0438 \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u044f \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u044e \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 this \u0432 \u043f\u043e\u043b\u0435 instance \u043a\u043b\u0430\u0441\u0441\u0430.<\/p>\n<p>  \u041f\u043e\u0434\u043e\u0431\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043c\u043e\u0436\u043d\u043e \u043e\u0431\u044a\u044f\u0432\u0438\u0442\u044c filter, constant \u0438 value.<\/p>\n<p>  <b>\u0421\u0431\u043e\u0440\u043a\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0430<\/b><\/p>\n<p>  \u0418\u0442\u0430\u043a, \u043c\u044b \u043d\u0430\u043f\u0438\u0441\u0430\u043b\u0438 \u043d\u0435\u043a\u0438\u0439 \u043a\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0440\u0430\u0437\u0431\u0438\u0442 \u043d\u0430 ES6 \u043c\u043e\u0434\u0443\u043b\u0438 \u0438 \u0442\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u043c \u043d\u0430\u0434\u043e \u0435\u0433\u043e \u0441\u043e\u0431\u0440\u0430\u0442\u044c \u0432\u043c\u0435\u0441\u0442\u0435. \u0417\u0430 \u043f\u043e\u0438\u0441\u043a \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439 \u043c\u043e\u0434\u0443\u043b\u0435\u0439 \u0438 \u0441\u0431\u043e\u0440\u043a\u0443 \u0438\u0445 \u0432 \u043e\u0434\u0438\u043d \u0444\u0430\u0439\u043b \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 Browserify. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043f\u0435\u0440\u0432\u044b\u043c \u0434\u0435\u043b\u043e\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u0442\u043e\u0447\u043a\u0443 \u0432\u0445\u043e\u0434\u0430, \u0441 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043d\u0430\u0447\u043d\u0435\u0442\u0441\u044f \u0441\u0431\u043e\u0440\u043a\u0430.<\/p>\n<p>  \u042f \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c 2 \u0442\u043e\u0447\u043a\u0438 \u0432\u0445\u043e\u0434\u0430- \u0442\u043e\u0447\u043a\u0443 \u0432\u0445\u043e\u0434\u044f \u043c\u043e\u0434\u0443\u043b\u044f \u2014 \u0442\u043e \u0435\u0441\u0442\u044c \u044d\u0442\u043e \u0444\u0430\u0439\u043b, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u0442 \u0432 \u0441\u0435\u0431\u044f \u043c\u043e\u0434\u0443\u043b\u0438\/\u0444\u0430\u0439\u043b\u044b \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0432\u043e\u0435\u0433\u043e \u043c\u043e\u0434\u0443\u043b\u044f \u0438 \u043e\u0431\u0449\u0443\u044e \u0442\u043e\u0447\u043a\u0443 \u0432\u0445\u043e\u0434\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0438\u0442 \u0432 \u0441\u0435\u0431\u044f \u0442\u043e\u0447\u043a\u0438 \u0432\u0445\u043e\u0434\u043e\u0432 \u043c\u043e\u0434\u0443\u043b\u0435\u0439.<\/p>\n<p>  \u041d\u043e \u0443 \u043c\u0435\u043d\u044f \u0442\u043e\u043b\u044c\u043a\u043e 1 \u043c\u043e\u0434\u0443\u043b\u044c \u0438 \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0442\u0430\u043a\u0438\u0445 \u0444\u0430\u0439\u043b\u043e\u0432 \u0442\u043e\u0436\u0435 \u0431\u0443\u0434\u0435\u0442 \u0432\u0441\u0435\u0433\u043e 2:  <\/p>\n<ol>\n<li>\u0424\u0430\u0439\u043b module.js, \u043d\u0430\u0445\u043e\u0434\u044f\u0449\u0438\u0439\u0441\u044f \u0432 \u043a\u043e\u0440\u043d\u0435 \u043f\u0430\u043f\u043a\u0438 account \u0438 \u0438\u043c\u0435\u044e\u0449\u0438\u0439 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u0432\u0441\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0435 \u0444\u0430\u0439\u043b\u044b \u043c\u043e\u0434\u0443\u043b\u044f <\/li>\n<li>\u0424\u0430\u0439\u043b app.js, \u043d\u0430\u0445\u043e\u0434\u044f\u0449\u0438\u0439\u0441\u044f \u0432 \u043a\u043e\u0440\u043d\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0438 \u0438\u043c\u0435\u044e\u0449\u0438\u0439 \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u0432\u0441\u0435 \u0444\u0430\u0439\u043b\u044b module.js \u043f\u0440\u043e\u0435\u043a\u0442\u0430<\/li>\n<\/ol>\n<p>  \u0412\u0442\u043e\u0440\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430- \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u0434 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0439 \u043d\u0430 ES6 \u0432 ES5. \u042d\u0442\u0443 \u0437\u0430\u0434\u0430\u0447\u0443 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0442\u044c Babel, \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u043d\u044b\u0439 \u043a Browserify \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u043b\u0430\u0433\u0438\u043d\u0430 c \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043e\u043f\u0446\u0438\u0438 transform. <\/p>\n<p>  \u041a\u043e\u0434 \u0441\u0431\u043e\u0440\u0449\u0438\u043a\u0430, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043a\u043e\u0434 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043d\u0430\u0439\u0442\u0438 \u0432 <a href=\"https:\/\/github.com\/SRobertZ\/es6angular\">\u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438 github<\/a>.<\/p>\n<p>  <b>\u041b\u0438\u0442\u0435\u0440\u0430\u0442\u0443\u0440\u0430:<\/b>  <\/p>\n<ol>\n<li><a href=\"https:\/\/docs.angularjs.org\/guide\">Guide to AngularJS Documentation<\/a> <\/li>\n<li><a href=\"http:\/\/habrahabr.ru\/post\/257305\/\">\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u0440\u0438\u0432\u0430\u0442\u043d\u044b\u0445 \u043f\u043e\u043b\u0435\u0439 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e WeakMap \u0432 JavaScript<\/a> <\/li>\n<li><a href=\"https:\/\/github.com\/gulpjs\/gulp\/blob\/master\/docs\/recipes\/fast-browserify-builds-with-watchify.md\">Fast browserify builds with watchify<\/a> <\/li>\n<\/ol>\n<div class=\"clear\"><\/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\/265847\/\"> http:\/\/habrahabr.ru\/post\/265847\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>             \u0412 \u0441\u0442\u0430\u0442\u044c\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043a\u0430\u043a \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043d\u0430 ES6 \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u0435 \u0447\u0430\u0441\u0442\u0438 AngularJs \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0437\u0430\u0442\u0435\u043c \u0441\u043e\u0431\u0440\u0430\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Browserify \u0438 Babel \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0441\u043a\u0430\u0447\u0430\u0442\u044c \u0441 <a href=\"https:\/\/github.com\/SRobertZ\/es6angular\">github<\/a> \u0438 \u043f\u043e\u0438\u0433\u0440\u0430\u0442\u044c\u0441\u044f.  <\/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-264686","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/264686","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=264686"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/264686\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=264686"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=264686"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=264686"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}