1.0.1 • Published 7 years ago

airbnb_javascript_helpers v1.0.1

Weekly downloads
3
License
MIT
Repository
github
Last release
7 years ago

Set of helpers to make it easier to follow one of the best JavaScript Style Guide.

#####Shortly: Do not call Object.prototype methods directly, such as hasOwnProperty, propertyIsEnumerable, and isPrototypeOf.

Why? These methods may be shadowed by properties on the object in question - consider { hasOwnProperty: false } - or, the object may be a null object (Object.create(null)).

// bad
console.log(object.hasOwnProperty(key));

// good
console.log(Object.prototype.hasOwnProperty.call(object, key));

// best
import { hasOwnProperty } from 'airbnb_javascript_helpers';

console.log(hasOwnProperty(object, key));

And this rule applies to all prototype methods.

Usage

npm i -S airbnb_javascript_helpers

####List of helpers:

Object

  • hasOwnProperty(obj, key)
  • isPrototypeOf(obj, arg)
  • propertyIsEnumerable(obj, prop)