What is the purpose of `constant.js` in d3-drag library?

314
February 03, 2017, at 10:21 AM

In having a bit of a look at the source code for the d3-drag javascript (es6) module, I've noticed there is a file called constant.js whose entire contents are:

export default function(x) {
  return function() {
    return x;
  };
}

This is imported in drag.js:

import constant from "./constant";

and then used (showing one of three similar instances):

drag.container = function(_) {
    return arguments.length ? (container = typeof _ === "function" ? _ : constant(_), drag) : container;
  };

Perhaps I just don't fully grok javascript in all its callback glory, but I don't quite understand the purpose of the constant.js module. Is someone able to shed a little light as to what's going on here?

READ ALSO
Verify authentication - Parse Cloud

Verify authentication - Parse Cloud

I want only the authenticated users to modify classes in the databaseFor example:

406
Issue upgrading ember 2.8 to 2.11 - cannot find module 'ember'

Issue upgrading ember 2.8 to 2.11 - cannot find module 'ember'

I believe this is somehow related to how Ember is now setup through npm instead of bower

398
How to get the name of an object in javascript

How to get the name of an object in javascript

Below code from URL (http://wwww3schools

613
Check ip status server online/offline

Check ip status server online/offline

How can I do to check if a server that contains ip and port is online at the moment or is offline ?, because I am with code but it not displays results in the ionic application

502