-
Notifications
You must be signed in to change notification settings - Fork 7
rauschma/class-js
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Class.js – tools for standard inheritance in JavaScript - Inspired by John Resig’s Simple Inheritance [1]. - Focus was on supporting constructor functions. Requirements: - Support the new operator - Support the instanceof operator - Support extending a class C via C.prototype - For a completely new approach to JavaScript inheritance take a look at "prototypes as classes" [2] [1] http://ejohn.org/blog/simple-javascript-inheritance/ [2] https://github.com/rauschma/proto-js ===== Code example ===== // Superclass var Person = Class.extend({ constructor: function (name) { this.name = name; }, describe: function() { return "Person called "+this.name; } }); // Subclass var Worker = Person.extend({ constructor: function (name, title) { Worker.super.constructor.call(this, name); this.title = title; }, describe: function () { return Worker.super.describe.call(this)+" ("+this.title+")"; // (*) } }); var jane = new Worker("Jane", "CTO");
About
Class.js – a simple JavaScript inheritance API
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published