google-code-export / jquery-formatcurrency

Automatically exported from code.google.com/p/jquery-formatcurrency
GNU General Public License v3.0
2 stars 0 forks source link

Scope resolution problem #34

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
formatCurrency = function( num ) {
    return $('<span />').text( num ).formatCurrency().text();
}

$('#button').on('click', function() {
    $this = $(this);
    for (i=1.5; i<=10.5; i++) {
        $this.parent().append('<p>'+formatCurrency(i)+'</p>');
    }
});

This code should create 10 paragraph tags, each with a different dollar amount, 
and append them to the parent of the #button element. However, because both 
this function and the plugin use "$this = $(this);" there is a scope issue, and 
my local variable $this gets overwritten.

While this issue can be corrected by changing my local code to an explicit 
declaration ("var $this = $(this);") the plugin should explicitly declare $this 
as a new variable to prevent this from happening.

Original issue reported on code.google.com by tyler.vi...@gmail.com on 3 Jul 2012 at 9:48