I have the following code:
let value = $(this).data('value');
value = System.decrypt(value, key);
$(this).data('value', value);
I’d like it to support chaining:
$(this)
.data('value', (value) => System.decrypt(value, key))
.css(…)
.prop(…);
But as far as I see, jQuery doesn’t have a lambda version of .data()
. Is there a simple way to achieve this, or I should write a plugin?
2
Answers
Well, I wrote the following simple helpers:
I see nothing wrong in getting the initial data beforehand, and setting it later (as in your first example).
If you want to modify the way the
.data()
method operates, you could rewrite it to accept a callback function to act as getter + setter and provide chainability, something among this lines:Example: