ãã®èšäºã§ã¯ãèè ã®ã·ã¹ãã ã«ã€ããŠèª¬æããŸããèè ã®ã·ã¹ãã ã¯ããæã§ãæžãããã¯ã©ã¹ïŒã€ãŸããäžçæéã®ã¯ã©ã¹ïŒã«å£ããªãé床ã§ãã ããããåæã«ãã¯ã©ã¹ã«ã¯çŽ æŽãããCã¹ã¿ã€ã«ã®æ§é ããããŸãã
ã¯ã©ã¹ã·ã¹ãã
ãã¹ãŠã®ããã°ã©ããŒãç¬èªã®ã¯ã©ã¹ã·ã¹ãã ãäœæããå¿ èŠããããšãããžã§ãŒã¯ããããŸãã åé¡ã«æ £ããŠããªã人- ãã®ã³ã¡ã³ããåç §ããŠãã ããã圌ãã¯å°ãªããšã50åãéããŸããã
ãããã®åãã€ã¯ã¯ããã®æ©èœã»ãããããã°ã©ãã³ã°ã¹ã¿ã€ã«ãé床ã®äœäžã«ãã£ãŠåºå¥ãããŸãã ããšãã°ãMooToolsã¯ã©ã¹ã®äœæã¯ãææžãã¯ã©ã¹ã®äœæãããçŽ90åé ããªããŸãã ãªããããã®ã·ã¹ãã ããã¹ãŠå¿ èŠãªã®ã§ããïŒ
å®éã«ã¯ãææžãã®ã¯ã©ã¹ãç¶æããã®ã¯éåžžã«é£ããããšãããããŸãã JSã¢ããªã±ãŒã·ã§ã³ãé©åãªãµã€ãºã«æé·ãããšããããã¿ã€ãã¯ä»¥åãšåãããã«ãã¯ãŒã«ãã§ã¯ãªããªããŸããããããèããŠã¿ãŠãã ãããããã©ãŒãã³ã¹ãå°ãç ç²ã«ããã ãã®äŸ¡å€ããããããããŸããããããã䜿ã£ãŠäœæ¥ããæ¹ãç°¡åã§ãã ããšãã°ããããã¿ã€ãã§èšè¿°ãããExt.JSãã©ã®ããã«èŠããããæ³åããŠãã ããã
泚ïŒäžéšã®æ·±å»ãªãããžã§ã¯ãã§ã¯ããŸã ã¯ã©ã¹ã·ã¹ãã ã䜿çšãããŠãããããã®åé¡ã¯ããã»ã©çºçããŠããŸããã äŸãšããŠ-ãœãŒã¹Derby.jsãåç §ããŠãã ããã ããããç§ã¯ããŒããŒãããªãã®ããã«äœãããããã©ãã¯ããã¯ã¹ã ãšæã£ãŠããã®ã§ãéçºè ã¯ãã®æ ¹æ§ãæãããšã匷ãå§ããŸããïŒæ£ãããªãå Žåã¯æ£ããïŒã Extã§ã¯ãéã«ãçžç¶ãéåžžã«éèŠã§ãã
ã·ã¹ãã ã®å©ç¹
ã·ã¹ãã ã«äœãæ±ããŸããïŒ ãŸããããã¯èŠªã¡ãœããã®åŒã³åºãã§ãã MooToolsã®äŸã次ã«ç€ºããŸãã
var Cat = new Class({ Extends: Animal, initialize: function(name, age){ this.parent(age); // } });
æåã¯éåžžã«èŠæ ãããããé¢æ°å ã«ã¯èŠªã¡ãœããããããŸãã ãŸãããªãã¡ã¯ã¿ãªã³ã°ã䟿å©ã§ããã¡ãœããã®ååãå€æŽããŠãã芪ã®åŒã³åºãã¯äžæããŸããã ããããçŸãããšå©äŸ¿æ§ã®ããã«ãããªãã¯å€§ããªä»£åãæããªããã°ãªããŸãã-ã¯ã©ã¹ã®åã¡ãœããã¯ãã®ãããªã²ã©ãããã±ãŒãžã«å ãŸããŸãïŒ
var wrapper = function(){ if (method.$protected && this.$caller == null) throw new Error('The method "' + key + '" cannot be called.'); var caller = this.caller, current = this.$caller; this.caller = current; this.$caller = wrapper; var result = method.apply(this, arguments); this.$caller = current; this.caller = caller; return result; }.extend({$owner: self, $origin: method, $name: key});
ããã¯éåžžã«é ãããšã¯èšããŸã§ããªãããããã°ã倧ãã劚ããŸã-ãã®ã¡ãœããã¯ãã¯ã©ã¹ã¡ãœãããåŒã³åºããããšãã«å®è¡ãããŸãã
ä»ã«äœãéèŠã§ããïŒ ã¯ã©ã¹ã®åã€ã³ã¹ã¿ã³ã¹ã«ã¯ãç¬èªã®ããããã£ãå¿ èŠã§ãã
var Cat = new Class({ food: [], initialize: function(name){ this.name = name; } }); var cat1 = new Cat(''); var cat2 = new Cat(''); // cat1.food.push(''); cat2.food.length == 0; //
ã芧ã®ãšãããMooToolsã¯ã¯ã©ã¹ããšã«ç¬èªã®é£ç©é åãäœæããŸããã åŸæ¥ã®ã¢ãããŒãã§ãããã©ã®ããã«è¡ãã®ã§ããããïŒ ã³ã³ã¹ãã©ã¯ã¿ãŒã§ããããã£ãå²ãåœãŠãŸãã
function Cat() { this.food = []; Cat.superclass.constructor.call(this) } Cat.prototype.meow = function() {/*...*/}
ã¡ãœããã«ã€ããŠã¯ãããã€ãã®ãªãã·ã§ã³ããããŸããäžèšã®äŸã¯ããã°ã©ã¹ã»ã¯ããã¯ãã©ãŒãã®æ¡åŒµæ©èœãåãããªãã·ã§ã³ã瀺ããŠããŸãã åŸæ¥ã®ã·ã¹ãã ã§ã¯ãã³ãŒãã«ã¯ãCat.prototype ...ãããsuperclass.constructor.callïŒthis ...ïŒããªã©ã®ã¬ããŒãžãããããããããã®ãããªã³ãŒãã¯èªèããªãã¡ã¯ã¿ãªã³ã°ãå°é£ã§ãã
ã¯ã©ã¹ã®éå ¬éã¡ã³ããŒã«ã€ããŠäžèš
C ++ã§çµ¶å¯Ÿã«æ£åžžãªããšã¯ãJavaScriptã§ã¯éåžžã«æ害ã§ãã ç§èªèº«ã®çµéšãããããèšããŸããã¯ã©ã¹ã«ãã©ã€ããŒããªã¡ãœãããšå€æ°ãããå Žåããã®ãããªã¯ã©ã¹ã¯ãã°ãã°ãµããŒããããªããªããŸãã ãã®ãããªã³ãŒãã®äžéšãå€æŽãããå Žåã¯ãå€ãã³ãŒããç Žæ£ããŠãã¹ãŠããŒãããæžãçŽããããåŸãªãå ŽåããããŸãã
ãã©ã€ããŒãã¡ã³ããŒã¯æªãç¿æ £ã§ãã ä¿è·ãããã¡ã³ããŒïŒåå㯠"_"ã§å§ãŸãïŒãæã£ãŠããã®ã¯æ£ããããšã§ãããŸããäžéšã®ç¿ãå€éšããã¡ã³ããŒãååŸãå§ããããšãæããŠããå Žåã¯ãããã圌ã®ããžãã¹ã§ãã 次ã«ãã¯ã©ã¹ãç¶æ¿ããããã°ã©ãããããããé ããŠããããšãããããŸãã ãããããããããªãã®ç®æšã§ãããã»ãšãã©ã®å Žåããã©ã€ããŒãã¡ã³ããŒã¯äœã解決ãããã¯ã©ã¹ãè€éã«ããé©åãªããã°ã©ããŒã«åé¡ãåŒãèµ·ããã ãã§ãã
ããã§ã¯ãC ++ãšåãããã䜿ããããããææžãã®ã¯ã©ã¹ãšåããããé«éãªã¯ã©ã¹ã·ã¹ãã ãäœæããŸãããã ãããŠãããªããã»ããµãªãã§åäœããŸãã
é«éã¯ã©ã¹ãæžã
ãã®ãããJSã§ã¯ã©ã¹ãäœæããæãéãæ¹æ³ã¯ããããã¿ã€ãã䜿çšããŠæã§äœæããããšã§ãã
function Animal() {} Animal.prototype.init = function() {}
ãã¹ãŠã®ãã©ãŠã¶ãšã³ãžã³ã¯ããã®æ¹æ³ã«æé©åãããŠããŸãã äžæ©åé²-ãããŠãäŸãã°ãããã©ãŒãã³ã¹ã®äœäžãååŸããŸãã
Animal.prototype = { init: function() {} }
ãã®äŸã§ã¯ããããã¿ã€ãããªããžã§ã¯ããšããŠå²ãåœãŠãããŸããã Chromeã¯ãããæ®éã«é£ã¹ãŸãããFirefoxã§ã¯ã¯ã©ã¹ã®äœæé床ãå€§å¹ ã«äœäžããŸãã
çŽ æ©ãç¶æ¿
次ã«ã芪ã¡ãœãããåŒã³åºãå¿ èŠããããŸãã ãããã¿ã€ããã§ãŒã³ããéããã®ã¯ãããŸããïŒ ãããŠã掟çã¯ã©ã¹ã®èŠªã¡ãœããã®ååãå€æŽããŸãããïŒ
function Cat() {} // Animal Cat.prototype.Animal$init = Animal.prototype.init; Cat.prototype.init = function() { this.Animal$init(); // }
芪ãããã¿ã€ãããã¡ãœãããã³ããŒããååãå€æŽããŸããã é«éåã¯ãã¯ãäžå¯èœã§ãã ãã¡ãããæäœæ¥ã§ã¯è¡ããŸãããã¯ã©ã¹ã·ã¹ãã ããã¹ãŠãè¡ããŸãã
ãã®äŸã§ã¯ãinstanceofæŒç®åã¯æ©èœããŸããããå®éã«ã¯ããããªãã§åé¡ãªãå®è¡ã§ããŸãã ç§ã¯å®éã®ã¢ããªã±ãŒã·ã§ã³ãšã¿ã¹ã¯ã«ã€ããŠè©±ããŠããŸããåç©ãšç«ã®ã¿ã€ããåºå¥ããå¿ èŠãããå Žåãããã¯å®éã®ã¿ã¹ã¯ã§ãããå®å šã«è§£æ±ºãããŠããŸãã ãã ããinstanceofæŒç®åã䜿çšããŠãããå®è¡ããå Žåã¯ãç³ãèš³ãããŸããããå¥ã®å»è ã«è¡ãå¿ èŠããããŸãã
ãã®ç¶æ¿ã§ãããããã¿ã€ããã§ãŒã³ã¯ãããŸããïŒãããã¿ã€ããã³ããŒãããããïŒ-ããã«ãããåŸæ¥ã®ãœãªã¥ãŒã·ã§ã³ã«æ¯ã¹ãŠãããã«é«éåãããŸãã
䟿å©ãªããããã£
ã³ã³ã¹ãã©ã¯ã¿ãŒã§ããã©ã«ãã®ããããã£ãæåã§å²ãåœãŠãããšããããŸãå¿«é©ã§ã¯ãããŸããã ãã®ãããMooToolsã®å Žåã®ããã«ãã¹ã¯ãªããã§ãããå®è¡ããŸãã ãããã©ã®ããã«æ©èœãããïŒã¯ã©ã¹ã·ã¹ãã èªäœããæ¢å®ã®ããããã£ãå²ãåœãŠãã³ã³ã¹ãã©ã¯ã¿ãŒé¢æ°ãçæããŸãã 次ã®ããã«ãªããŸãã
ClassManager.define( 'Cat', { Extends: 'Animal', food: [], init: function() { this.Animal$init(); } });
ãã®çµæã以äžãåŸãããŸãã
// function Cat() { this.food = []; this.init.apply(this, arguments); } // Cat.prototype.Animal$init = Animal.prototype.init; Cat.prototype.init = init: function() { this.Animal$init(); }
ãªãŒããŒã©ã€ãããã芪ã¡ãœããã¯ããã®èŠåã«åŸã£ãŠååãå€æŽãããŸãã
<__> + "$" + <_>
ãã®ãããªæ§æã¯ãç§ãã¡ãé床ã«å¯ŸããŠæ¯æã£ãæå°ã®ãã®ã§ãããå®éã«ã¯äžäŸ¿ããåŒãèµ·ããããšã¯ãããŸããã ãããŠãã¯ã©ã¹èªäœã¯ãã£ããŒã¹ããã®ã«é©ããŠããŸãããããããèŠãã®ãè¯ãããšã§ãã
ã¯ã©ã¹ãããŒãžã£ãŒ
ä»ãç§ã®æ±ºå®ã®å°ãPRã é床ãã¹ããClassManager察NativeïŒ jsperfãžã®ãªã³ã¯ ïŒïŒ
ã¯ã©ã¹ã®äœæé床ã®éãã¯ãjsperfãšã©ãŒã«èµ·å ããå¯èœæ§ããããŸãïŒå€ãã°ã©ãã§ã¯ããã¹ãŠã®ãã¹ãã±ãŒã¹ã§åãã§ãïŒã æ å ±ã«ã€ããŠïŒå®éã«ã¯ã2ã€ã®ç°ãªããã¹ããšããŠå®è¡ãããŠããåãã³ãŒããã20ïŒ ã®é床差ã§å®è¡ãããããšããããŸããã
Nativeã¡ãœããã®åŒã³åºããéåžžã«é ãçç±-ããã¯ããèšããŸãïŒ
NativeChildClass.prototype.method = function() { NativeParentClass.prototype.method.apply(this); }
ç¬èªã®ãããã¿ã€ãããã®åŒã³åºããšé©çšã«ããåŒã³åºãã®é床ã®éãã¯ãããã«ããããŸãã ç§ãããã§æ°ããããã«æãããªããããããããªãã®ãã¹ããæžããŠãã ããããšã«ããéããªããŸããã
ãããšã¯å¥ã«ãFirefoxã«ã€ããŠèšåãã䟡å€ããããŸãããã©ãŠã¶ãŒã§çæãããã¯ã©ã¹ã®äœæã¯ãã¯ããã«é ããªããŸããïŒç§ã®å€ãã©ãããããã§ã¯-æ¯ç§40äžåã®æäœã®ã¿ïŒã ããããç§ã®ClassManagerã䜿çšãããšããµãŒããŒäžã§ã¯ã©ã¹ãæ§ç¯ã§ããŸããFFã§ã¯ãNativeãããããã«é«éã«åäœããŸãã ããã«ãããã«ããããŒãžã®èªã¿èŸŒã¿ãé«éåãããŸãã
ClassManagerãšä»ã®ã·ã¹ãã
åºç€ãšããŠãèè ã®ãã¹ãDotNetWiseã䜿çšããŸãããã...圌ã®ãã¹ãã¯æå°æªã§ãããã¯ã©ã¹çæãšã¡ãœããã«ãã500åã®å埩ããã¹ãããŠããŸãã ãç解ã®ãšãããçæãããã³ãŒãã®å質ãšé床ã¯çæãããæéã«äŸåããããã¹ããããåãã¬ãŒã ã¯ãŒã¯ã«ã€ããŠããã®æç¹ã§ç¬èªã®ãšã©ãŒãçºçããŸãã ããã«ãç§ã®ã¯ã©ã¹ã¯ãµãŒããŒäžã§çµã¿ç«ãŠãããšãã§ããŸãã
ãããã£ãŠãæåã«ã¯ã©ã¹ãäœæããŠãããã¹ãããæ¹ãã¯ããã«å ¬å¹³ã§ãã ãŸããã¯ã©ã¹ã®çææéãæ¯èŒããå¿ èŠãããå Žåã¯ãã¡ãœããåŒã³åºãã®é床ã«è¿œå ããã®ã§ã¯ãªãããã®ããã®åå¥ã®ãã¹ããäœæããã®ãæ£ããã§ãããã
å ã®ãã¹ãã§ã¯-èè ã®ã·ã¹ãã DNWã¯ãã¡ãããªãŒãããŸãã ãã ãããã¹ããä¿®æ£ãããšãChromeã§ClassManagerãæåã«è¡šç€ºããã次ã«FiberãDNWã衚瀺ãããŸãã FFã§ã¯ãTypeScriptãæåã«æ¥ãŠã次ã«ãã€ãã£ãã次ã«ClassManagerãæ¥ãŸãã ããã§ããããã¯éåžžã«å ·äœçãªãã¹ãã§ããããã§ã¯ãã¯ã©ã¹ã®äœæãã¡ãœããã®åŒã³åºããšãšãã«ïŒééã£ãæ¯çã§ïŒæž¬å®ããããããå®éã®ç¶æ³ãåæ ããŠããªããšæããŸãã ãã ãã ãªã³ã¯ãšçµæã¯æ¬¡ã®ãšããã§ãã
ClassManagerã®æ©èœ
ãŸããéåžžã«éèŠãªè©³çŽ°ããå§ããŸããIDEã®ããŒã«ãããã¯ã¯ã©ã¹ã§æ©èœããŸãïŒ å°ãªããšãã»ãšãã©ã®å ŽåïŒç§ã¯PhpStormã䜿çšããŠããŸãïŒã ã¯ã©ã¹ã®å€èŠ³ã®äŸã次ã«ç€ºããŸãã
Lava.ClassManager.define( // , 'Lava.Animal', { // on(), _fire() Extends: 'Lava.mixin.Observable', // : // Implements: 'Lava.mixin.Observable', name: null, toys: [], // - init: function(name) { this.name = name; }, takeToy: function(toy) { this.toys.push(toy) } }); Lava.ClassManager.define( 'Lava.Cat', { Extends: 'Lava.Animal', // , Shared: ['_shared'], // , _shared: { likes_food: ['', ''] }, breed: null, init: function(name, breed) { this.Animal$init(name); this.breed = breed; }, eat: function(food) { if (this._shared.likes_food.indexOf(food) != -1) { // , Lava.mixin.Observable this._fire('eaten', food); } } }); var cat = new Lava.Cat('', ''); // - Lava.mixin.Observable cat.on('eaten', function(garfield, food) { console.log(' ' + food); }, {}); cat.eat(''); // " "
æšæºãã£ã¬ã¯ãã£ãïŒ
- æ¡åŒµ-çŽæ¥ç¶æ¿ã åå«ã¯ã1ã€ã®èŠªããã®ã¿ç¶æ¿ã§ããŸãã
- å®è£ -ããã¯ã¹ã€ã³ããã³å€éç¶æ¿çšã ããã¯ã¹ã€ã³ã®åå«ããããã£ãšã¡ãœãããä¿æããŸãããã¯ã©ã¹ã§åå®çŸ©ããããã¹ãŠãåªå ãããŸãã
- Shared-ãããã¿ã€ãã«ãªããžã§ã¯ãããããããŸãã ããã©ã«ãã§ã¯ãã¯ã©ã¹ã®æ¬äœå ã®ãã¹ãŠã®ãªããžã§ã¯ãã¯ã€ã³ã¹ã¿ã³ã¹ããšã«ã³ããŒãããŸãããå ±æããããšã¯ã§ããŸãã
ããŒãã¹ïŒ
- ãªã³ã¶ãã©ã€ããã³éçã³ã³ã¹ãã©ã¯ã¿ãŒã§ã¯ã©ã¹ã¡ãœããã«ããããé©çšããããšãã§ããŸãã ããšãã°ãIEå ã«ãã°ä¿®æ£ãé©çšããä»ã®ãã©ãŠã¶ã§ãããç¡å¹ã«ãããå Žåã ã¯ã©ã¹ã³ã³ã¹ãã©ã¯ã¿ãŒã§ãã¯ã©ã¹ãç¶æ¿ãã§ãŒã³ã®éäžã«ããå Žåã§ããå¿ èŠãªã¡ãœãããéžæããŠãããã¿ã€ãã§çœ®ãæããããšãã§ããŸãã
- çæãããã¯ã©ã¹ããšã¯ã¹ããŒãããŸãã ãµãŒããŒã§ã³ã³ã¹ãã©ã¯ã¿ãŒãçæã§ããŸããããã«ãããããŒãžã®ããŒãæéãç¯çŽãããFirefoxã§ã®ãªããžã§ã¯ãã®äœæãé«éåãããŸãã
- åå空éãšããã±ãŒãžã 詳现ã«ã€ããŠã¯ããã¥ã¡ã³ãããèªã¿ãã ããã
èšç»ã§ã¯ããã®ãããªä¿®é£Ÿåãæœè±¡ããã³æçµãšããŠè¿œå ããŸãã
çæïŒ
- ããã§ãSharedãã£ã¬ã¯ãã£ãã¯ãªããžã§ã¯ãã®ã¿ïŒé åã§ã¯ãªãïŒããããã¿ã€ãã«è»¢éã§ããŸãã äžæçãªè§£æ±ºçãšããŠãé åããããã£ã䜿çšããŠãªããžã§ã¯ããäœæã§ããŸããããã¯å°ãäžäŸ¿ã§ãã æ¹èšã®ã¿ã¹ã¯ããããŸããããŸã åªå äºé ã§ã¯ãããŸããã
- ãããŠãããé¡èãªæ¬ ç¹ïŒã¯ã©ã¹ã¡ã³ããŒã®ååãå§çž®ã§ããããŒã«ã¯ãããŸããïŒåã«ååãå€æŽãããšã芪ã¡ãœããã®åŒã³åºããäžæããŸãïŒã ãããäœæããèšç»ããããŸããããã¯ç¢ºãã«è¡šç€ºãããŸãããææ¥ã¯è¡šç€ºãããŸããã èå³æ·±ãããšã«ãç§ããããèªåã§èšããªãã£ãå Žåãããªãã¯ããã«æ³šæãæããŸããïŒ
å ¥æå
ã¹ã¿ã³ãã¢ãã³ããŒãžã§ã³ã¯ãã®ãªããžããªã«ãããŸã ã ãŸããã¡ã€ã³ãã¬ãŒã ã¯ãŒã¯Webãµã€ããžã®ãªã³ã¯ããããŸããåªããããã¥ã¡ã³ãïŒè±èªïŒããããã³ãŒãå ã®äŸã確èªã§ããŸãããŸããObservableïŒã€ãã³ãïŒãPropertiesïŒã€ãã³ããæã€ããããã£ïŒãEnumerableïŒ "live ãé åãã
PS
ã¯ããã¡ãªã¿ã«ãã¡ã€ã³ãã¬ãŒã ã¯ãŒã¯ã¯LiquidLavaãšåŒã°ããAngularãšEmberã«ä»£ããæè¯ã®éžæè¢ãšããŠäœæãããŸããã é¢çœãïŒ
UPD
ã³ã¡ã³ããä¿®æ£ããŠãããŸããïŒapplyãcallã«çœ®ãæãããšãNativeã¡ãœããã®åŒã³åºãé床ãäžããããšãã§ããŸãã æåã®ClassManager察Nativeãã¹ããæŽæ°ãããŸãããFFã§ã¯ãNativeã¡ãœããã®åŒã³åºãé床ã¯ClassManagerã®é床ãšåãã§ããããChromeã§ã¯ãŸã è¥å¹²å£ã£ãŠããŸãã