Javascript-форум (https://javascript.ru/forum/)
-   Оффтопик (https://javascript.ru/forum/offtopic/)
-   -   Унылого треша тред (https://javascript.ru/forum/offtopic/47728-unylogo-tresha-tred.html)

cyber 29.12.2013 06:57

Цитата:

Сообщение от Maxmaxmaximus6
оцените ридми=)

:lol:

DjDiablo 29.12.2013 13:14

Оценил.
Особенно понравилось.

Цитата:

Вообще, так писать даже правильнее, чем просто Cat =) потом поймете почему.
Цитата:

Вот эти вот все атрибуты называются директивы. Они что-то делают.
Цитата:

Вот и вся суть ui - пишем директивы, пишем фигурные скобки
Цитата:

Азы вы поняли

Не одного комментария в коде нету. Настоящий мужик ! Комментарии для слабаков.

Maxmaxmaximus6 29.12.2013 16:06

Цитата:

Сообщение от DjDiablo
Не одного комментария в коде нету. Настоящий мужик !

Спасибо, мой код не нуждается в комментариях =)

Maxmaxmaximus7 11.01.2014 00:35

Пасоны, глядите я новый 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

Vlasenko Fedor 11.01.2014 00:56

Явно здесь не был
http://www.typescriptlang.org/Playground/

Maxmaxmaximus7 11.01.2014 01:18

Poznakomlus, да да, но это препроцессор а у меня подключаешь один файлик и все работает.

Maxmaxmaximus7 11.01.2014 01:47

хм. Да, если кто нас читает то я оговорился) это транслятор.

Poznakomlus, послушай, я знаю про тайпскрипт.

Maxmaxmaximus7 11.01.2014 01:50

Чо-то мне кажется это слишком медленно, так что завязываю и снова возвращаюсь к 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();

melky 11.01.2014 02:22

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

Maxmaxmaximus7 11.01.2014 05:39

melky, чит =)


Часовой пояс GMT +3, время: 06:06.