CoreObject

3.1.5 · abandoned · verified Sun Apr 19

CoreObject is a JavaScript library providing a lightweight, robust implementation of an OOP Class model. It was primarily developed for and used within the Ember-CLI ecosystem to define and extend classes, facilitating a structured approach to object-oriented programming in JavaScript. The package supports Node.js environments from version 4 onwards. While the latest public version is 3.1.5, its last major update was published approximately nine years ago, indicating that the project is currently abandoned. Consequently, there is no active release cadence, and it is not recommended for new projects seeking ongoing maintenance, security updates, or modern JavaScript features. Its primary value now lies in its historical context within legacy Ember-CLI applications, where it continues to function as a core utility.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates defining a base class, extending it, creating instances, and dynamically adding methods using `reopen`.

import CoreObject from 'core-object';

// Define a base class
const Animal = CoreObject.extend({
  init() {
    this._super(...arguments);
    this.name = 'Unnamed';
  },
  sayHello() {
    console.log(`Hello, I am ${this.name}.`);
  }
});

// Extend the base class
const Dog = Animal.extend({
  init(name) {
    this._super(...arguments);
    this.name = name || 'Fido';
  },
  bark() {
    console.log(`${this.name} says Woof!`);
  },
  sayHello() {
    this._super(...arguments);
    this.bark();
  }
});

// Create instances
const genericAnimal = Animal.create();
genericAnimal.sayHello(); // Output: Hello, I am Unnamed.

const myDog = Dog.create('Buddy');
myDog.sayHello(); // Output: Hello, I am Buddy.\nBuddy says Woof!
myDog.bark(); // Output: Buddy says Woof!

// Demonstrating `reopen` for adding methods dynamically
Dog.reopen({
  fetch() {
    console.log(`${this.name} is fetching!`);
  }
});

myDog.fetch(); // Output: Buddy is fetching!

view raw JSON →