sonygod / sharpkit

Automatically exported from code.google.com/p/sharpkit
0 stars 0 forks source link

$CreateAnonymousDelegate overwrites global delegate variable #100

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
> What steps will reproduce the problem?
var delegate = 1;
$CreateAnonymousDelegate = function (target, func) {
    if (target == null || func == null) return func;
    delegate = function () {
        return func.apply(target, arguments);
    };
    delegate.func = func;
    delegate.target = target;
    delegate.isDelegate = true;
    return delegate;
}
var ad = $CreateAnonymousDelegate({}, function () {});
/* now delegate contains function instead of 1 */

> What is the expected output? What do you see instead?
The global "delegate" variable should not be modified by the 
$CreateAnonymousDelegate function.

> What version of the product are you using? On what operating system?
SharpKit v4.24.3000

>Please provide any additional information below.

The issue can be easy solved by adding "var" before the "delegate =" string:

    var delegate = function () {
        return func.apply(target, arguments);
    };

Thanks,
Alex

Original issue reported on code.google.com by alex.net...@gmail.com on 9 Feb 2012 at 7:40

GoogleCodeExporter commented 9 years ago

Original comment by DanelK...@gmail.com on 10 Feb 2012 at 1:25