简体   繁体   English

为什么这种方法无法按我预期的那样工作?

[英]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. 我在自学Java脚本/ jQuery,并在使用jQuery UI的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. 我有一个可运行的方法moveLabel ,但没有按我期望的那样工作-我无法以我认为应该的方式调用它。

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 . 这是当前的CodePen

I also tried to move the mousemove event into the method also to no success (gist). 我也尝试将mousemove事件移入方法中也没有成功(要点)。

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). 它具有函数rangeslider() ,该函数接受一个参数(名称将不同)。

Here in your code it takes moveLabel as a parameter. 在您的代码中,它以moveLabel作为参数。

Now you can call this function through the class object self . 现在,您可以通过类对象self调用此函数。

While in your second try you are treating moveLabel() as a function which is nowhere exist in the library class. 在第二次尝试中,您将moveLabel()视为一个函数,该函数在库类中不存在。 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 谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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