Hello

I have this similar code:

var SomeVar = Class.create({
    one: null,
    two: null,
    three: null,

initialize: function(one, two) {
        this.one = one;
        this.two = two;

    },

startListeners: function() {


        $j('#somediv1').mousedown(function(e) {


        this.three=3;
        three="hi"



        }.bind(this));


    $j('#somediv2').mousedown(function(e) {


        console.log(this.three);
        console.log(three);



        }.bind(this));
    },

});

As you see there are more can one variable called "three". What is the best way to have one common variable named three where I can modifiy it freely and it does not get deleted/destroyed everytime I do a mousedown on divone then on divtwo it comes out null.

It may be related but what the hell is "}.bind(this));"?

Recommended Answers

All 2 Replies

Member Avatar for LastMitch

What is the best way to have one common variable named three where I can modifiy it freely and it does not get deleted/destroyed everytime I do a mousedown on divone then on divtwo it comes out null.

I don't think you can.

The only way is a workaround that you can change from one to two to three and so forward.

I also don't think there a work around either.

You can look at this:

https://gist.github.com/hallettj/64478

There has to be a workaround.

Ive come up with a solution anyhow.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.