_.debounce doesnt work as expected

Aldarund

I want to use lodash debounce() function. Here is the simplest example.

var update_from = function (name) {
            console.log(name);
 };
$( document ).ready(function() {
  _.debounce(update_from, 1500)("first");
  _.debounce(update_from, 1500)('second');
  _.debounce(update_from, 1500)("third");
});

I expect only "third" to be printed into console. But all three are printed.

What am I doing wrong or misunderstanding? According this article, this should work like I expect, but it doesn't.

Here is plunkr with that example: http://plnkr.co/edit/OCDAChkMes97XcMLJSag?p=preview

barry-johnson

You're creating and executing three separate debounced functions, not one debounced function three times.

var myFunc = _.debounce(update_from, 1500);
myFunc('first');
myFunc('second');
myFunc('third');

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

_.debounce doesnt work as expected

From Dev

getElementsByTagName() method doesnt work as expected

From Dev

getElementsByTagName() method doesnt work as expected

From Dev

DrawerLayout lock mode doesnt work as expected

From Dev

jquery show/hide scale doesnt work as expected

From Dev

Why variable assignation doesnt work as expected?

From Dev

Php, DI, references doesnt work as expected

From Dev

Ember.run.debounce with immediate argument does not work as expected

From Dev

Django i18n_patterns: resolve() doesnt work as expected

From Dev

ember.js using itemController with each helper doesnt work as expected

From Dev

css3 rotation with nth-child doesnt work as expected

From Dev

std::nothrow doesnt work as expected - Condition is always false

From Dev

C# action block await doesnt work as expected

From Dev

cpp string find() doesnt work as expected - returns big junk values

From Dev

Why debounce doesnt invoke my function?

From Dev

Cannot get _.debounce() to work

From Dev

String.Contains doesnt work as expected with folders returned by Directory.GetDirectories

From Dev

POST doesnt work

From Dev

method click doesnt work

From Dev

PendingIntent doesnt work

From Dev

BufferedWaveProvider doesnt work in Unity

From Dev

$(this) doesnt work within a function?

From Dev

JQuery hover doesnt work

From Dev

Node command doesnt work

From Dev

jQuery toggle doesnt work

From Dev

ImageField doesnt work

From Dev

Dajax example doesnt work

From Dev

Bootstrap dropdown doesnt work

From Dev

Angular Databinding doesnt Work