{"id":15547324,"url":"https://github.com/uhop/dcl","last_synced_at":"2025-10-03T12:46:30.876Z","repository":{"id":2423222,"uuid":"3391960","full_name":"uhop/dcl","owner":"uhop","description":"Elegant minimalistic implementation of OOP with mixins + AOP in JavaScript for node.js and browsers.","archived":false,"fork":false,"pushed_at":"2024-06-13T03:25:37.000Z","size":3210,"stargazers_count":76,"open_issues_count":2,"forks_count":10,"subscribers_count":10,"default_branch":"master","last_synced_at":"2024-12-10T11:40:58.749Z","etag":null,"topics":["aop-advices","es5-classes","mixins-aop","oop"],"latest_commit_sha":null,"homepage":"http://www.dcljs.org/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/uhop.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":"AUTHORS","dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"uhop","buy_me_a_coffee":"uhop"}},"created_at":"2012-02-08T22:11:23.000Z","updated_at":"2024-06-13T03:25:40.000Z","dependencies_parsed_at":"2024-06-18T17:05:40.652Z","dependency_job_id":"6d323220-6cda-483f-a1fa-32bf91ffeb62","html_url":"https://github.com/uhop/dcl","commit_stats":{"total_commits":224,"total_committers":5,"mean_commits":44.8,"dds":0.46875,"last_synced_commit":"6c4d5592152410151a9825618226fa078fa8c260"},"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uhop%2Fdcl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uhop%2Fdcl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uhop%2Fdcl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uhop%2Fdcl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/uhop","download_url":"https://codeload.github.com/uhop/dcl/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":229144630,"owners_count":18026910,"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":["aop-advices","es5-classes","mixins-aop","oop"],"created_at":"2024-10-02T13:08:40.161Z","updated_at":"2025-10-03T12:46:25.815Z","avatar_url":"https://github.com/uhop.png","language":"JavaScript","readme":"# `dcl`\n\n\n[![Build status][travis-image]][travis-url]\n[![NPM version][npm-image]][npm-url]\n\n[![Greenkeeper][greenkeeper-image]][greenkeeper-url]\n[![Dependencies][deps-image]][deps-url]\n[![devDependencies][dev-deps-image]][dev-deps-url]\n\nA minimalistic yet complete JavaScript package for [node.js](http://nodejs.org)\nand modern browsers that implements OOP with mixins + AOP at both \"class\" and\nobject level. Implements [C3 MRO](http://www.python.org/download/releases/2.3/mro/)\nto support a Python-like multiple inheritance, efficient supercalls, chaining,\nfull set of advices, and provides some useful generic building blocks. The whole\npackage comes with an extensive test set, and it is fully compatible with the strict mode.\n\nThe package was written with debuggability of your code in mind. It comes with\na special debug module that explains mistakes, verifies created objects, and helps\nto keep track of AOP advices. Because the package uses direct static calls to super\nmethods, you don't need to step over unnecessary stubs. In places where stubs are\nunavoidable (chains or advices) they are small, and intuitive.\n\nBased on ES5, the `dcl 2.x` works on Node and all ES5-compatible browsers. It fully\nsupports property descriptors, including AOP advices for getters and setters,\nas well as regular values. If your project needs to support legacy browsers,\nplease consider `dcl 1.x`.\n\nThe library includes a small library of useful base classes, mixins, and advices.\n\nThe main hub of everything `dcl`-related is [dcljs.org](http://www.dcljs.org/),\nwhich hosts [extensive documentation](http://www.dcljs.org/docs/).\n\n# Examples\n\nCreate simple class:\n\n```js\nvar A = dcl({\n  constructor: function (x) { this.x = x; },\n  m: function () { return this.x; }\n});\n```\n\nSingle inheritance:\n\n```js\nvar B = dcl(A, {\n  // no constructor\n  // constructor of A will be called automatically\n\n  m: function () { return this.x + 1; }\n});\n```\n\nMultiple inheritance with mixins:\n\n```js\nvar M = dcl({\n  sqr: function () { var x = this.m(); return x * x; }\n});\n\nvar AM = dcl([A, M]);\nvar BM = dcl([B, M]);\n\nvar am = new AM(2);\nconsole.log(am.sqr()); // 4\n\nvar bm = new BM(2);\nconsole.log(bm.sqr()); // 9\n```\n\nSuper call:\n\n```js\nvar AMSuper = dcl([A, M], {\n  m: dcl.superCall(function (sup) {\n    return function () {\n      return sup.call(this) + 1;\n    };\n  })\n});\n\nvar ams = new AMSuper(3);\nconsole.log(ams.sqr()); // 16\n```\n\nAOP advices:\n\n```js\nvar C = dcl(AMSuper, {\n  constructor: dcl.advise({\n    before: function (x) {\n      console.log('ctr arg:', x);\n    },\n    after: function () {\n      console.log('this.x:', this.x);\n    }\n  }),\n  m: dcl.after(function (args, result, makeReturn) {\n    console.log('m() returned:', result);\n    // let's fix it\n    makeReturn(5);\n  })\n});\n\nvar c = new C(1);\n// prints:\n// ctr arg: 1\n// this.x: 1\nconsole.log(c.sqr());\n// prints:\n// m() returned: 2\n// 25\n```\n\nSuper call with getters:\n\n```js\nvar G = dcl({\n  constructor: function (x) { this._x = x; },\n  get x () { return this._x; }\n});\n\nvar g = new G(1);\nconsole.log(g.x); // 1\n\nvar F = dcl(G, {\n  x: dcl.prop({\n    get: dcl.superCall(function (sup) {\n      return function () {\n        return sup.call(this) + 1;\n      };\n    })\n  })\n});\n\nvar f = new F(1);\nconsole.log(f.x); // 2\n```\n\nAdvise an object:\n\n```js\nfunction D (x) { this.x = x; }\nD.prototype.m = function (y) { return this.x + y; }\n\nvar d = new D(1);\nconsole.log(d.m(2)); // 3\n\nadvise(d, 'm', {\n  before: function (y) { console.log('y:', y); },\n  around: function (sup) {\n    return function (y) {\n      console.log('around');\n      return 2 * sup.call(this, y + 1);\n    };\n  },\n  after: function (args, result) {\n    console.log('# of args:', args.length);\n    console.log('args[0]:', args[0]);\n    console.log('result:', result);\n  }\n});\n\nconsole.log(d.m(2));\n// prints:\n// y: 2\n// around\n// # of args: 1\n// args[0]: 2\n// result: 8\n```\n\nAdditionally `dcl` provides a small library of predefined\n[base classes](http://www.dcljs.org/2.x/docs/bases/),\n[mixins](http://www.dcljs.org/2.x/docs/mixins/),\nand [useful advices](http://www.dcljs.org/2.x/docs/advices/). Check them out too.\n\nFor more examples, details, howtos, and why, please read [the docs](http://www.dcljs.org/docs/).\n\n# How to install\n\nWith `npm`:\n\n```\nnpm install --save dcl\n```\n\nWith `yarn`:\n\n```\nyarn add dcl\n```\n\nWith `bower`:\n\n```\nbower install --save dcl\n```\n\n## How to use\n\n`dcl` can be installed with `npm`, `yarn`, or `bower` with files available from\n`node_modules/` or `bower_components/`. By default, it uses UMD, and ready\nto be used with Node's `require()`:\n\n```js\n// if you run node.js, or CommonJS-compliant system\nvar dcl = require('dcl');\nvar advise = require('dcl/advise');\n```\n\n[Babel](https://babeljs.io/) can have problems while compiling UMD modules, because it appears to generate calls to `require()` dynamically. Specifically for that `dcl` comes with a special ES6 distribution located in `\"/es6/\"` directory:\n\n```js\n// ES6 FTW!\nimport dcl from 'dcl/es6/dcl';\nimport advise from 'dcl/es6/advise';\n```\n\n*Warning:* make sure that when you use Babel you include `dcl/es6` sources into the compilation set usually by adding `node_modules/dcl/es6` directory.\n\nIt can be used with AMD out of box:\n\n```js\n// if you use dcl in a browser with AMD (like RequireJS):\nrequire(['dcl'], function (dcl) {\n    // the same code that uses dcl\n});\n\n// or when you define your own module:\ndefine(['dcl'], function (dcl) {\n\t// your dcl-using code goes here\n});\n```\n\nIf you prefer to use globals in a browser, include files with `\u003cscript\u003e` from `/dist/`:\n\n```html\n\u003cscript src='node_modules/dcl/dist/dcl.js'\u003e\u003c/script\u003e\n```\n\nAlternatively, you can use https://unpkg.com/ with AMD or globals. For example:\n\n```html\n\u003cscript src='https://unpkg.com/dcl@latest/dist/dcl.js'\u003e\u003c/script\u003e\n```\n\n# Documentation\n\n`dcl` is extensively documented in [the docs](http://www.dcljs.org/docs/).\n\n# Versions\n\n## 2.x\n\n- 2.0.11 \u0026mdash; *Technical release.*\n- 2.0.10 \u0026mdash; *Refreshed dev dependencies.*\n- 2.0.9 \u0026mdash; *Refreshed dev dependencies, removed `yarn.lock`.*\n- 2.0.8 \u0026mdash; *Added AMD distro.*\n- 2.0.7 \u0026mdash; *A bugfix. Thx [Bill Keese](https://github.com/wkeese)!*\n- 2.0.6 \u0026mdash; *Bugfixes. Thx [Bill Keese](https://github.com/wkeese)!*\n- 2.0.5 \u0026mdash; *Regenerated ES6 distro.*\n- 2.0.4 \u0026mdash; *Refreshed dev dependencies, fixed ES6 distro.*\n- 2.0.3 \u0026mdash; *Added ES6 distro.*\n- 2.0.2 \u0026mdash; *Small stability fix + new utility: registry.*\n- 2.0.1 \u0026mdash; *Small corrections to README.*\n- 2.0.0 \u0026mdash; *The initial release of 2.x.*\n\n## 1.x\n\n- 1.1.3 \u0026mdash; *1.x version before forking for 2.x*\n\n# License\n\nBSD or AFL \u0026mdash; your choice.\n\n[npm-image]:         https://img.shields.io/npm/v/dcl.svg\n[npm-url]:           https://npmjs.org/package/dcl\n[deps-image]:        https://img.shields.io/david/uhop/dcl.svg\n[deps-url]:          https://david-dm.org/uhop/dcl\n[dev-deps-image]:    https://img.shields.io/david/dev/uhop/dcl.svg\n[dev-deps-url]:      https://david-dm.org/uhop/dcl?type=dev\n[travis-image]:      https://img.shields.io/travis/uhop/dcl.svg\n[travis-url]:        https://travis-ci.org/uhop/dcl\n[greenkeeper-image]: https://badges.greenkeeper.io/uhop/dcl.svg\n[greenkeeper-url]:   https://greenkeeper.io/\n","funding_links":["https://github.com/sponsors/uhop","https://buymeacoffee.com/uhop"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuhop%2Fdcl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fuhop%2Fdcl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuhop%2Fdcl/lists"}