Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

es5-class-ployfill

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

es5-class-ployfill

Use Class-likely in es5

  • 0.1.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

es5-class-ployfill

Use Class-likely in es5 Inspired by http://ejohn.org/blog/simple-javascript-inheritance/

Install

Node.js 4 or higher

$ npm install es5-class-ployfill --save

Usage

var Class = require('es5-class-ployfill');

// Shape
var Shape = Class.extend({
  constructor: function() {
    this.x = 0;
    this.y = 0;
  },

  move: function(x, y) {
    this.x += x;
    this.y += y;
    console.info('Shape moved.');
  },

  echo: function() {
    console.log('I am Shape.');
  }
});

// Rectangle
var Rectangle = Shape.extend({
  constructor: function(w, h) {
    this.w = w;
    this.h = h;

    this._super();
  },

  move: function(x, y) {
    this._super(x, y);
    console.info('Rectangle moved.');
  },

  area: function() {
    console.log('Area is', this.w * this.h);
  },

  echo: function() {
    console.log('I am Rectangle.');
  }
});

// Square
var Square = Rectangle.extend({
  constructor: function(w) {
    this._super(w, w);
  },

  echo: function() {
    console.log('I am Square.');
  }
});

var rect = new Rectangle(2, 4);
var square = new Square(4);

console.log('Is rect an instance of Rectangle?', rect instanceof Rectangle);// true
console.log('Is rect an instance of Shape?', rect instanceof Shape);// true
console.log('Is rect an instance of Square?', rect instanceof Square);// false
rect.echo(); // Outputs, 'I am Rectange.'
rect.move(1, 1); // Outputs, 'Shape moved. Rectangle moved.'
rect.area(); // Outputs, 'Area is 8'

console.log('Is square an instance of Square?', square instanceof Square);// true
console.log('Is square an instance of Rectangle?', square instanceof Rectangle);// true
console.log('Is square an instance of Shape?', square instanceof Shape);// true
square.echo(); // Outputs, 'I am Square.'
square.area(); // Outputs, 'Area is 16'

API

Class.extend(proto)

proto

Define Function prototype, especially proto.constructor is Function constructor

Keywords

FAQs

Package last updated on 16 Jun 2016

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc