{"id":20963832,"url":"https://github.com/codemix/classing","last_synced_at":"2025-07-05T05:34:49.316Z","repository":{"id":17481835,"uuid":"20262483","full_name":"codemix/classing","owner":"codemix","description":"Fluent classes for node.js and the browser.","archived":false,"fork":false,"pushed_at":"2019-11-07T17:16:04.000Z","size":43,"stargazers_count":6,"open_issues_count":1,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-06-22T18:53:00.029Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/codemix.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-05-28T15:24:33.000Z","updated_at":"2020-09-30T02:34:38.000Z","dependencies_parsed_at":"2022-09-02T12:11:24.502Z","dependency_job_id":null,"html_url":"https://github.com/codemix/classing","commit_stats":null,"previous_names":["codemix/classer"],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/codemix/classing","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codemix%2Fclassing","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codemix%2Fclassing/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codemix%2Fclassing/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codemix%2Fclassing/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codemix","download_url":"https://codeload.github.com/codemix/classing/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codemix%2Fclassing/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263381189,"owners_count":23458164,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-19T02:48:33.597Z","updated_at":"2025-07-05T05:34:49.287Z","avatar_url":"https://github.com/codemix.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Classing\n\n[![Build Status](https://travis-ci.org/codemix/classing.svg?branch=master)](https://travis-ci.org/codemix/classing)\n\nEasy, flexible classes for JavaScript, works in node and all modern browser (\u003e IE8).\n\n# Why another class library?\n\nBecause none of the other class libs have a good way to associate meta data with properties, and have that meta data easily available in child classes. This is useful for e.g. defining property labels, types, validation rules etc.\n\nClassing presents an API similar to the native `Object.defineProperty()` and `Object.defineProperties()` methods.\n\n```js\n\nvar Class = require('classing');\n\nvar User = Class();\n\nUser.defineProperty('name', {\n  label: 'Name',\n  value: 'anonymous'\n});\n\nUser.defineProperties({\n  email: {\n    label: 'Email Address'\n  },\n  avatarUrl: {\n    label: 'Avatar URL',\n    // getter\n    get: function () {\n      return getGravatarUrl(this.email);\n    }\n  }\n\n});\n\n\nvar user = new User({\n  name: 'charles',\n  email: 'foo@example.com'\n});\n\nconsole.log(User.descriptors.name.label + ':', user.name); // \"Name: charles\"\n\nconsole.log(user.avatarUrl);\n\n```\n\nThe main difference between this and the native methods is that the full descriptor declarations are preserved. The native methods discard these extra keys (anything other than `enumerable`, `configurable`, `writable`, `value`, `get` and `set`), making them unsuitable for storing metadata. Classing corrects this and ensures that the descriptors are accessible within child classes.\n\n\n# Installation\n\nVia [npm](https://npmjs.org/package/classing):\n\n    npm install --save classing\n\n\nor [bower](http://bower.io/search/?q=classing):\n\n\n    bower install --save classing\n\n\n\n# Usage\n\n\n\n**Simple classes**\n\n```js\nvar Class = require('classing');\n\nvar Person = Class({\n  name: {\n    value: 'No Name'\n  },\n  dateOfBirth: {}\n});\n\nvar person = new Person();\n\nperson.name === 'No Name'; // =\u003e true\n\nvar person = new Person({\n  name: 'Bob',\n  dateOfBirth: new Date()\n});\n```\n\n**Default values**\n\n```js\nvar Collection = Class({\n  items: {\n    enumerable: false,\n    default: function () { return []; }\n  },\n  length: {\n    get: function () {\n      return this.items.length;\n    }\n  },\n  push: function () {\n    return this.items.push.apply(this.items, arguments);\n  }\n});\n\nvar list = new Collection();\n\nlist.length === 0; // true\n\nlist.push(1, 2, 3);\n\nlist.length === 3; // true\n\n\n```\n\n**Inheritance**\n\n```js\nvar Vehicle = Class({\n  name: {\n    value: 'No Name'\n  }\n});\n\nvar RoadVehicle = Vehicle.extend({\n  wheels: {\n    value: 0\n  },\n  capacity: {\n    value: 0\n  },\n  capacityPerWheel: {\n    get: function () {\n      return (this.capacity || 1) / (this.wheels || 1)\n    }\n  }\n});\n\nvar Car = RoadVehicle.extend({\n  wheels: {\n    value: 4\n  }\n});\n\nvar mini = new Car({\n  name: 'mini',\n  capacity: 28\n});\n\nconsole.log(mini.capacityPerWheel);\n\n```\n\n\n**Mixins**\n\n```js\n\nvar Truck = RoadVehicle.extend();\n\nTruck.mixin({\n  capacity: 2,\n  wheels: 8\n});\n\nvar truck = new Truck();\nconsole.log(truck.capacityPerWheel);\n\n\n```\n\n\n**Auto Binding**\n\n```js\nvar MyConsole = Class.create({\n  alert: {\n    bind: true,\n    value: function (message) {\n      this.alertCalledCount++;\n      console.warn(message);\n    }\n  },\n  log: {\n    bind: console,\n    value: console.log\n  },\n  alertCalledCount: {\n    value: 0\n  }\n});\n\nvar myconsole = new MyConsole(),\n    alert = myconsole.alert,\n    log = myconsole.log;\n\nmyconsole.alertCalledCount.should.equal(0);\n\nalert('Hello');\nalert('World');\n\nmyconsole.alertCalledCount.should.equal(2);\n\nlog('If you can see this in the console, it worked.');\n\n```\n\n# Running the tests\n\nFirst, `npm install`, then `npm test`. Code coverage generated with `npm run coverage`.\n\n\n# License\n\nMIT, see [LICENSE.md](LICENSE.md).\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodemix%2Fclassing","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodemix%2Fclassing","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodemix%2Fclassing/lists"}