Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow event handlers registered with one() to be removed with off(). #659

Closed
wants to merge 2 commits into from
Closed

Conversation

delner
Copy link

@delner delner commented Jul 29, 2013

Fixes #658

@@ -329,8 +329,10 @@ vjs.trigger = function(elem, event) {
* @return {[type]}
*/
vjs.one = function(elem, type, fn) {
vjs.on(elem, type, function(){
var func = function(){
vjs.off(elem, type, arguments.callee);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

while we're at it, can we get rid of arguments.callee since it has been deprecated?
We should be able to just put func in there instead.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, that'd be good. Would there be an issue with the var func being assigned after the function is created?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be fine since the function gets called after func has been defined.
For example:

var foo = function() {
  console.log(foo.toString());
};
foo();
// function() { console.log(foo.toString()); }

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, thanks.

@heff
Copy link
Member

heff commented Jul 29, 2013

@delner Mind making that small change, and then I'll pull it in?

@delner
Copy link
Author

delner commented Jul 29, 2013

Should be good to go; test worked fine on my fork.

@gkatsev
Copy link
Member

gkatsev commented Jul 29, 2013

👍

@heff
Copy link
Member

heff commented Jul 29, 2013

Nice!

@heff heff closed this in 334ff59 Jul 29, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

vjs.one() event listening cannot be turned off with vjs.off()
4 participants