Carrying scope of "this" into inner functions

Posted by Matrym on Stack Overflow See other posts from Stack Overflow or by Matrym
Published on 2011-03-02T23:20:45Z Indexed on 2011/03/02 23:25 UTC
Read the original article Hit count: 192

Filed under:
|
|
|

How can I extend the scope of this inward? I thought reassigning a higher scoped variable would do the trick... what am I doing wrong? http://jsfiddle.net/8bqXM/

function Player(configs) {

    this.opts = {
        playerID: "cSurf"
    };
    configs = $.extend(this.opts, configs);

    var the = this;

    this.init = function(){
        var $player = $("#" + the.configs.playerID);
        alert($player.attr("id"));
    }
}
var cSurf = new Player();
$(document).ready(function(){
        cSurf.init();
});

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery