{"_id":"cls","_rev":"43898","name":"cls","description":"Class factory featuring inheritance of static properties, static constructors, lazy population of prototypes, and this._super.","dist-tags":{"latest":"0.1.5"},"maintainers":[{"name":"benjamn","email":""}],"time":{"modified":"2021-06-03T10:13:25.000Z","created":"2013-06-15T18:56:33.900Z","0.1.5":"2014-05-26T18:09:57.451Z","0.1.4":"2014-04-02T22:01:15.163Z","0.1.3":"2013-06-15T20:35:55.540Z","0.1.2":"2013-06-15T20:16:01.416Z","0.1.1":"2013-06-15T20:06:58.772Z","0.1.0":"2013-06-15T18:56:33.900Z"},"users":{"zhangyaochun":true},"author":{"name":"Ben Newman","email":"bn@cs.stanford.edu"},"repository":{"type":"git","url":"git://github.com/benjamn/cls.git"},"versions":{"0.1.5":{"author":{"name":"Ben Newman","email":"bn@cs.stanford.edu"},"name":"cls","description":"Class factory featuring inheritance of static properties, static constructors, lazy population of prototypes, and this._super.","keywords":["class","inheritance","static","lazy","super","prototype","extend"],"version":"0.1.5","homepage":"http://github.com/benjamn/cls","repository":{"type":"git","url":"git://github.com/benjamn/cls.git"},"license":"MIT","main":"main.js","scripts":{"test":"node ./node_modules/mocha/bin/mocha --reporter spec"},"dependencies":{},"devDependencies":{"mocha":"~1.18.2"},"engines":{"node":">= 0.6"},"bugs":{"url":"https://github.com/benjamn/cls/issues"},"_id":"cls@0.1.5","dist":{"shasum":"df3218cf9d1480747f584d88b19b74c6b281317b","size":5551,"noattachment":false,"key":"/cls/-/cls-0.1.5.tgz","tarball":"http://registry.cnpm.dingdandao.com/cls/download/cls-0.1.5.tgz"},"_from":".","_npmVersion":"1.4.3","_npmUser":{"name":"benjamn","email":"bn@cs.stanford.edu"},"maintainers":[{"name":"benjamn","email":""}],"directories":{},"publish_time":1401127797451,"_cnpm_publish_time":1401127797451,"_hasShrinkwrap":false},"0.1.4":{"author":{"name":"Ben Newman","email":"bn@cs.stanford.edu"},"name":"cls","description":"Class factory featuring inheritance of static properties, static constructors, lazy population of prototypes, and this._super.","keywords":["class","inheritance","static","lazy","super","prototype","extend"],"version":"0.1.4","homepage":"http://github.com/benjamn/cls","repository":{"type":"git","url":"git://github.com/benjamn/cls.git"},"main":"main.js","scripts":{"test":"node ./node_modules/mocha/bin/mocha --reporter spec"},"dependencies":{},"devDependencies":{"mocha":"~1.18.2"},"engines":{"node":">= 0.6"},"bugs":{"url":"https://github.com/benjamn/cls/issues"},"_id":"cls@0.1.4","dist":{"shasum":"209e3531edaed42c97107dc7d78c1f86a868a97b","size":4792,"noattachment":false,"key":"/cls/-/cls-0.1.4.tgz","tarball":"http://registry.cnpm.dingdandao.com/cls/download/cls-0.1.4.tgz"},"_from":".","_npmVersion":"1.4.3","_npmUser":{"name":"benjamn","email":"bn@cs.stanford.edu"},"maintainers":[{"name":"benjamn","email":""}],"directories":{},"publish_time":1396476075163,"_cnpm_publish_time":1396476075163,"_hasShrinkwrap":false},"0.1.3":{"author":{"name":"Ben Newman","email":"bn@cs.stanford.edu"},"name":"cls","description":"Class factory featuring inheritance of static properties, static constructors, lazy population of prototypes, and this._super.","keywords":["class","inheritance","static","lazy","super","prototype","extend"],"version":"0.1.3","homepage":"http://github.com/benjamn/cls","repository":{"type":"git","url":"git://github.com/benjamn/cls.git"},"main":"main.js","scripts":{"test":"whiskey test/run.js"},"dependencies":{"whiskey":"0.6.x"},"devDependencies":{},"optionalDependencies":{"whiskey":"0.6.x"},"engines":{"node":">= 0.6"},"readmeFilename":"README.md","bugs":{"url":"https://github.com/benjamn/cls/issues"},"_id":"cls@0.1.3","dist":{"shasum":"4a896404e6e5a99bf6bb966000b4fd4c27e19b0b","size":4006,"noattachment":false,"key":"/cls/-/cls-0.1.3.tgz","tarball":"http://registry.cnpm.dingdandao.com/cls/download/cls-0.1.3.tgz"},"_from":".","_npmVersion":"1.2.30","_npmUser":{"name":"benjamn","email":"bn@cs.stanford.edu"},"maintainers":[{"name":"benjamn","email":""}],"directories":{},"publish_time":1371328555540,"_cnpm_publish_time":1371328555540,"_hasShrinkwrap":false},"0.1.2":{"author":{"name":"Ben Newman","email":"bn@cs.stanford.edu"},"name":"cls","description":"Class factory featuring inheritance of static properties, static constructors, lazy population of prototypes, and this._super.","keywords":["class","inheritance","static","lazy","super","prototype","extend"],"version":"0.1.2","homepage":"http://github.com/benjamn/cls","repository":{"type":"git","url":"git://github.com/benjamn/cls.git"},"main":"main.js","scripts":{"test":"whiskey test/run.js"},"dependencies":{"whiskey":"0.6.x"},"devDependencies":{},"optionalDependencies":{"whiskey":"0.6.x"},"engines":{"node":">= 0.6"},"readmeFilename":"README.md","bugs":{"url":"https://github.com/benjamn/cls/issues"},"_id":"cls@0.1.2","dist":{"shasum":"9460c9b2b77b1ae787ddafc9ed84808badf09555","size":3902,"noattachment":false,"key":"/cls/-/cls-0.1.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/cls/download/cls-0.1.2.tgz"},"_from":".","_npmVersion":"1.2.30","_npmUser":{"name":"benjamn","email":"bn@cs.stanford.edu"},"maintainers":[{"name":"benjamn","email":""}],"directories":{},"publish_time":1371327361416,"_cnpm_publish_time":1371327361416,"_hasShrinkwrap":false},"0.1.1":{"author":{"name":"Ben Newman","email":"bn@cs.stanford.edu"},"name":"cls","description":"Class factory featuring inheritance of static properties, static constructors, lazy population of prototypes, and this._super.","keywords":["class","inheritance","static","lazy","super","prototype","extend"],"version":"0.1.1","homepage":"http://github.com/benjamn/cls","repository":{"type":"git","url":"git://github.com/benjamn/cls.git"},"main":"main.js","scripts":{"test":"whiskey test/run.js"},"dependencies":{"whiskey":"0.6.x"},"devDependencies":{},"optionalDependencies":{"whiskey":"0.6.x"},"engines":{"node":">= 0.6"},"readmeFilename":"README.md","bugs":{"url":"https://github.com/benjamn/cls/issues"},"_id":"cls@0.1.1","dist":{"shasum":"8044508373acd6c4cd2e0c7c3e82fd522306069d","size":3897,"noattachment":false,"key":"/cls/-/cls-0.1.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/cls/download/cls-0.1.1.tgz"},"_from":".","_npmVersion":"1.2.30","_npmUser":{"name":"benjamn","email":"bn@cs.stanford.edu"},"maintainers":[{"name":"benjamn","email":""}],"directories":{},"publish_time":1371326818772,"_cnpm_publish_time":1371326818772,"_hasShrinkwrap":false},"0.1.0":{"author":{"name":"Ben Newman","email":"bn@cs.stanford.edu"},"name":"cls","description":"Class factory featuring inheritance of static properties, static constructors, lazy population of prototypes, and this._super.","keywords":["class","inheritance","static","lazy","super","prototype","extend"],"version":"0.1.0","homepage":"http://github.com/benjamn/cls","repository":{"type":"git","url":"git://github.com/benjamn/cls.git"},"main":"main.js","scripts":{"test":"whiskey test/run.js"},"dependencies":{"whiskey":"0.6.x"},"devDependencies":{},"optionalDependencies":{"whiskey":"0.6.x"},"engines":{"node":">= 0.6"},"bugs":{"url":"https://github.com/benjamn/cls/issues"},"_id":"cls@0.1.0","dist":{"shasum":"4722aa290bc5cad819e1ba47b90b0eec57579b32","size":2845,"noattachment":false,"key":"/cls/-/cls-0.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/cls/download/cls-0.1.0.tgz"},"_from":".","_npmVersion":"1.2.30","_npmUser":{"name":"benjamn","email":"bn@cs.stanford.edu"},"maintainers":[{"name":"benjamn","email":""}],"directories":{},"publish_time":1371322593900,"_cnpm_publish_time":1371322593900,"_hasShrinkwrap":false}},"readme":"Introduction\n---\n\nStandardized `class` syntax\n[is coming](http://wiki.ecmascript.org/doku.php?id=strawman:maximally_minimal_classes)\nin ECMAScript 6, supposedly, but until then I need a class factory that fills the gap.\n\nFor me that means (in no particular order):\n\n* prototypal inheritance under the hood\n* access to overridden properties (`super`)\n* inheritance of `static` properties\n* `static` constructors\n* close correspondence to ES6 syntax\n* ES5/browser compatibility\n* only-pay-for-what-you-use performance\n* excellent test coverage: [![Build Status](https://travis-ci.org/benjamn/cls.png?branch=master)](https://travis-ci.org/benjamn/cls)\n\nI have no delusions of persuading the world to use this tool. Just try\n`npm search inheritance` some time to see how many other people have come\nup with solutions that work for them.\n\nIf you have a special interest in the tired me-too sport of\npure-JavaScript class factory implementations, you might find this one\ninteresting for its solutions to each of the requirements listed above,\nparticularly the lazy (just-in-time) population of prototype properties.\n\nNote that I did not mention privacy enforcement as a requirement. If you\nneed a mechanism like the `private` keyword in other languages, I have a\nseparate [project](https://npmjs.org/package/private) that works\nseamlessly alongside this one.\n\nInstallation\n---\nFrom NPM:\n\n    npm install cls\n\nFrom GitHub:\n\n    cd path/to/node_modules\n    git clone git://github.com/benjamn/cls.git\n    cd cls\n    npm install .\n\nUsage\n---\n\nOne example will have to suffice for now:\n```js\nvar cls = require(\"cls\");\n\nvar BaseClass = cls.extend({\n    init: function(a, b) {\n        this.sum = a + b;\n    },\n\n    getSum: function() {\n        return this.sum;\n    },\n\n    statics: {\n        name: \"BaseClass\",\n\n        init: function(cls) {\n            cls.zero = new cls(0, 0);\n        }\n    }\n});\n\nvar SubClass = BaseClass.extend({\n    init: function(arg) {\n        this._super(arg, arg);\n        this.sum += 1;\n    },\n\n    statics: {\n        name: \"SubClass\"\n    }\n});\n\nassert(BaseClass.name === \"BaseClass\");\nassert(SubClass.name === \"SubClass\");\n\nassert(new BaseClass(2).getSum() === 4);\nassert(new SubClass(2).getSum() === 5);\n\nassert(SubClass.zero !== BaseClass.zero);\nassert(SubClass.zero instanceof SubClass);\nassert(SubClass.zero.getSum() === 1);\n```\nFor more complex examples, see `test/run.js`.\n","_attachments":{},"homepage":"http://github.com/benjamn/cls","bugs":{"url":"https://github.com/benjamn/cls/issues"},"license":"MIT"}