简体   繁体   中英

Why is this method not working as I would expect?

I'm teaching myself java-script/jQuery and I'm writing a range slider plugin using jQuery UI's Widget Factory + HTML5/CSS. I have a method moveLabel that is working but not as I would expect it to - I can't invoke it the way I thought I should be able.

This works:

self.on('mousemove', function(e) {
    self.rangeslider('moveLabel');
});

I expected this to work:

self.moveLabel();

Can someone explain to me what the difference is and why the previous works and the latter does not (and/or point me towards sources)? This is the current CodePen .

I also tried to move the mousemove event into the method also to no success (gist).

The first code which worked stated:-

The third-party library using class concept.

It has function rangeslider() which accepts one parameter(would be different-names).

Here in your code it takes moveLabel as a parameter.

Now you can call this function through the class object self .

While in your second try you are treating moveLabel() as a function which is nowhere exist in the library class. And hens it's not working.

Note:- A third-party library comes into picture after thousand of test-checks and modification,so i don't think there is any better way to use that function/parameter. So go with first-one itself. Thanks

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM