Цитата:
|
Оценил.
Особенно понравилось. Цитата:
Цитата:
Цитата:
Цитата:
Не одного комментария в коде нету. Настоящий мужик ! Комментарии для слабаков. |
Цитата:
|
Пасоны, глядите я новый Class написал =)
Пасоны, глядите я новый Class написал =)
function Class( description ) { return Class.extend( description ); } Class.extend = function( description ) { description.prototype = this.prototype; var prototype = new description; var constructor = prototype.constructor || function() {}; constructor.prototype = prototype; constructor.extend = this.extend; return constructor; }; // используем var Animal = new Class(function() { this.say = function() { alert( this.name ) } }); var Cat = Animal.extend(function() { this.constructor = function() { this.name = 'Cat'; } }) var Rabbit = Animal.extend(function() { this.constructor = function() { this.name = 'Rabbit'; } }) var q = new Cat(); var w = new Rabbit(); q.say(); // Cat w.say(); // Rabbit щас добавлю сахар для перекрытия и обращения к полям без this Чтобы можно было писать так var Animal = new Class( function() { constructor = function() { name = 'Animal' age = 11 } say = function() { alert( name ) } } ); и имелось ввиду именно обращение к this А добавлю перекрытие чтобы к перекрытым родительским можно было обращаться как parent.method |
Явно здесь не был
http://www.typescriptlang.org/Playground/ |
Poznakomlus, да да, но это препроцессор а у меня подключаешь один файлик и все работает.
|
хм. Да, если кто нас читает то я оговорился) это транслятор.
Poznakomlus, послушай, я знаю про тайпскрипт. |
Чо-то мне кажется это слишком медленно, так что завязываю и снова возвращаюсь к UI.js
function Class( description ) { return Class.extend( description ); } Class.extend = function( description ) { description = parse( description ); description.prototype = this.prototype; var prototype = new description; if (prototype.hasOwnProperty( 'constructor' )) { var constructor = prototype.constructor } else { var constructor = function() {} } constructor.prototype = prototype; constructor.prototype.parent = description.prototype; constructor.extend = this.extend; return constructor; }; function parse( description ) { var code = description.toString().match( /\{([\s\S]*)\}/ )[1]; var regExp = /parent[\s]*\.[\s]*(\w+)[\s]*\((.*?)\)/img; code = code.replace( regExp, function( match, method, params ) { var callText = /\S/.test( params ) ? '.call(this,' : '.call(this'; return 'parent.' + method + callText + params + ')'; } ); code = 'with(this){' + code + '}'; return new Function( code ); } // ИСПОЛЬЗУЕМ Animal = Class.extend( function() { this.say = function() { alert( 'animal' ) } } ); Cat = Animal.extend( function() { this.say = function() { parent.say(); alert( 'cat' ); } } ) new Cat().say(); |
function parse( description ) { var code = description.toString().match( /\{([\s\S]*)\}/ )[1]; var regExp = /parent[\s]*\.[\s]*(\w+)[\s]*\((.*?)\)/img; code = code.replace( regExp, function( match, method, params ) { var callText = /\S/.test( params ) ? '.call(this,' : '.call(this'; return 'parent.' + method + callText + params + ')'; } ); code = 'with(this){' + code + '}'; return new Function( code ); } :D |
melky, чит =)
|
Часовой пояс GMT +3, время: 06:06. |