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

core-object

Package Overview
Dependencies
Maintainers
7
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

core-object

A lightweight implementation of OOP Class in JavaScript

  • 3.1.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
206K
decreased by-0.33%
Maintainers
7
Weekly downloads
 
Created

What is core-object?

The core-object npm package provides a base class for creating objects with properties and methods, supporting inheritance and mixins. It is commonly used in JavaScript applications to create structured, reusable components.

What are core-object's main functionalities?

Creating a Basic Class

This feature allows you to create a basic class with properties and methods. The `extend` method is used to define a new class, and the `create` method is used to instantiate an object of that class.

const CoreObject = require('core-object');

const Person = CoreObject.extend({
  init(name, age) {
    this.name = name;
    this.age = age;
  },
  introduce() {
    return `Hi, I'm ${this.name} and I'm ${this.age} years old.`;
  }
});

const john = Person.create('John', 30);
console.log(john.introduce()); // Hi, I'm John and I'm 30 years old.

Inheritance

This feature demonstrates inheritance, where a new class can extend an existing class, inheriting its properties and methods. The `Dog` class extends the `Animal` class and overrides the `speak` method.

const CoreObject = require('core-object');

const Animal = CoreObject.extend({
  init(name) {
    this.name = name;
  },
  speak() {
    return `${this.name} makes a noise.`;
  }
});

const Dog = Animal.extend({
  speak() {
    return `${this.name} barks.`;
  }
});

const dog = Dog.create('Rex');
console.log(dog.speak()); // Rex barks.

Mixins

This feature shows how to use mixins to add additional functionality to a class. The `CanFly` mixin is added to the `Bird` class, providing the `fly` method.

const CoreObject = require('core-object');

const CanFly = {
  fly() {
    return `${this.name} is flying.`;
  }
};

const Bird = CoreObject.extend(CanFly, {
  init(name) {
    this.name = name;
  }
});

const eagle = Bird.create('Eagle');
console.log(eagle.fly()); // Eagle is flying.

Other packages similar to core-object

FAQs

Package last updated on 24 Aug 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

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