npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

functions-in-es6

v0.0.1

Published

A walk through and tests and Reflection for different kinds of functions in JavaScript till ES2015 spec.

Downloads

5

Readme

functions-in-es6

A walk through and tests and Reflection for different kinds of functions in JavaScript till ES2015 spec.

Run tests

Using Node

npm test

Using v8

cd src
/path/to/d8 v8-d8.js

(or) if you have d8 in your $PATH,

npm run v8

How it started ?

The idea is to detect from a reference the type of function - arrow, class or a normal function. And to detect before instantiating if the reference is instantiable.

  • https://github.com/facebook/react/issues/4599
  • http://stackoverflow.com/a/31947622/556124

This repository is about defining the function getFunctionType which returns the type of function input -

  • arrow
  • class
  • method
  • generator
  • function

Definitions

Source: http://stackoverflow.com/a/31947622/556124

  • arrow functions are functions that cannot be used as constructors, and don't have a .prototype property. However, methods don't either. They inherit from Function.prototype.
  • classes are functions that can be called without new, and that have a .prototype object which is normally not empty. If extend was used, they don't inherit from Function.prototype.
  • functions are functions that can be called either way, and do have a .prototype that is normally empty. They inherit from Function.prototype.
  • generator functions are functions that do have a .prototype which inherits from the intrinsic GeneratorPrototype object, and they inherit from the intrinsic Generator object.

Implementation

getFunctionType.js

Assumptions and other gotchas

NO TRANSPILING

  • Don't transpile this using babel or traceur. It will give your absolutely wrong results.

Requires ES6 features

  • arrows
  • generators
  • classes
  • enhanced object literals
  • let, const
  • Map
  • Array.prototype.startsWith
  • etc...

Function with prototypes is a class

// this will be treated as a class
function x() {}
x.prototype.a = function() {}

// this is a simple function
function y() {}

methods are detected as methods only when declared as methods

// either via enhanced object literals
let x = {
  method() {}
};

// or via class
class x {
  method() {}
}

I don't know anyway to detect the following as a method yet.

function y() {}
y.prototype.method = function() {};