🚀 DAY 4 OF LAUNCH WEEK:Introducing Socket Scanning for OpenVSX Extensions.Learn more →
Socket
Book a DemoInstallSign in
Socket

es-abstract-has-property

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

es-abstract-has-property

A method to determine whether an object has a property with the specified property key. The property may be either an own or inherited. This method follows ECMAScript's specification for the 'HasProperty' abstract operation.

latest
Source
npmnpm
Version
0.1.0
Version published
Maintainers
1
Created
Source

HasProperty

A method to determine whether an object has a property with the specified property key. The property may be either an own or inherited. This method follows ECMAScript's specification for the 'HasProperty' abstract operation.

Currently, this module only supports the ES2017 (ES8) specification.

Why?

While working on a module, I found myself with a need to reproduce ECMAScript internal methods and abstract operations. I wanted smaller, modular code instead of a larger library.

Installation Using npm

npm install es-abstract-has-property

Example Usage

var hasProperty = require('es-abstract-has-property');

function Animal(obj){
  this.animalInstanceMethod_A = function alfa(a) {}
  this.init.apply(this, arguments)
}
Animal.prototype.init = function animalInit() {
  this.animalInstanceMethod_B = function bravo(b) {}
}
Animal.animalStaticMethod = function charlie(c) {}
Animal.prototype.animalPrototypeMethod = function delta(d) {}

function Cat(){
  this.init.apply(this, arguments)
}
Cat.prototype = Object.create(Animal.prototype)
Cat.prototype.constructor = Cat
Cat.prototype.init = function catInit() {
  Animal.prototype.init.call(this)
  this.catInstanceMethod = function echo(e) {}
}

var c = new Cat()
console.log(c.hasOwnProperty("animalPrototypeMethod")) // => false
console.log(hasProperty(c, "animalPrototypeMethod"))   // => true
console.log(hasProperty(c, "animalInstanceMethod_A"))  // => false
console.log(hasProperty(c, "animalInstanceMethod_B"))  // => true
console.log(hasProperty(c, "animalStaticMethod"))      // => false

Documentation

API

HasProperty(O, P)

Determine whether an object has a property with the specified property key. The property may be either an own or inherited.

A Boolean value is returned.

O

Type: Object

The object being checked. Values will be coerced using Object(O), allowing for the checking of properties such as "length" on a string primitive.

P

Type: String

The property key to look for on the object.

  • es-abstract: a single library for multiple ECMAScript abstract operations.

Keywords

HasProperty

FAQs

Package last updated on 28 Jul 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts