Javascript method chaining working but convoluted

Paul

I am wondering if there is a simpler way to have an item from a list faded out then removed than this:

$('li').on('click', function() {
  $(this).fadeOut(2000, function(){this.remove();});
});

It works, but seems a bit convoluted. Thanks.

Derek 朕會功夫

The most you can do is probably this:

$("li").on("click", function(){
    $(this).fadeOut(2000, this.remove);
});

jQuery already did most of the abstraction for you and there isn't really much you can do to shorten it. Remember this is not code golf - you don't get points for using the shortest code.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Method chaining using javascript not working?

From Dev

Method chaining using javascript not working?

From Dev

chaining async method calls - javascript

From Dev

JavaScript Method Chaining or Angular $q

From Dev

Generic type inference not working with method chaining?

From Dev

How to sleep a method in javascript method chaining

From Dev

How to sleep a method in javascript method chaining

From Dev

Is javascript Promise API more convoluted than it needs to be?

From Dev

Method chaining with the same method

From Dev

How do I Apply chaining method on javascript document.createElement

From Dev

Javascript - Can indentation on method chaining cause issues with semicolons?

From Dev

Is it possible to start method chaining on a new line after a variable name in JavaScript?

From Dev

javascript first() method not working

From Dev

Call method is not working in javascript

From Dev

javascript method not working in chrome

From Dev

Non convoluted method to add a new line after ng-repeat

From Dev

.on("hover", ...) chaining not working

From Dev

ContinueWith chaining not working as expected

From Dev

Chaining not working on jQuery Plugin

From Dev

Optional Chaining Not Working As Expected

From Dev

CABasicAnimation chaining not working

From Dev

chaining ifelse with mutate not working

From Dev

Swift - Method chaining

From Dev

Method chaining in ruby

From Dev

Return type for method chaining

From Dev

Python class method chaining

From Dev

Method Chaining and Class Inheritance

From Dev

Method chaining with asyncio coroutines

From Dev

Method Chaining based on condition