, this — , — , . ?var self = this;var self = this;
asyncFunc(function () {
    self.callMethod();
});$('input').bind('keydown', function () {
    var $this = $(this);
    $this.css({
        background : $this.val()
    });
});var killmeplz = this;var self = this;
asyncFunc(function () {
    var self2 = this; // wtf ?!!
    setTimeout(function () {
        self.callMethod(self2);
    }, 200);
});$('input').bind('keydown', function () {
    var $colorInput = $(this);
    $colorInput.css({
        background : $colorInput.val()
    });
});$block = $(this);
$('button').each(function () {
    var $button = $(this);
    $.each(users, function () {
        var user = this;
        $block.append(user.init($button));
    });
});Function.prototype.bind = function (scope) {
    var fn = this;
    return function () {
        return fn.apply(scope, arguments);
    };
};asyncFunc(function () {
    this.callMethod();
}.bind(this));var Analizer = new Class({
    initialize : function (name) {
        this.dataRouter = new DataRouter[name]();
    },
    start : function () {
        var analizer   = this;
        this.dataRouter.get(function (data) {
            analizer.parse(data);
        });
    },
    parse : function (data) {
        // parsing data, using this.privateMethods
    }
});dataGetter.get(analizer.parse);var Analizer = new Class({
    initialize : function (name) {
        this.dataRouter = new DataRouter[name]();
    },
    start : function () {
        this.dataRouter.get(
            this.parse.bind(this)
        );
    },
    parse : function (data) {
        // parsing data, using this.privateMethods
    }
});Bridge.AI = new Class({
    // ..
    putCardSmart : function (card) {
        this.putCard( card,
            //       ,    .
            this.finishSmart.bind(this)
        );
    },
    getCardSmart : function () {
        this.getCard(function (card) {
            this.canPutCard(card) ?
                this.putCardSmart(card) :
                this.finishSmart();
        }.bind(this)); //   .
    },
    finishSmart : function () {
        this.canFinishMove() ?
            this.finishMove() :
            this.movement();
    }
    // ..
});Source: https://habr.com/ru/post/103760/
All Articles