{"_id":"classtool","_rev":"4659317","name":"classtool","description":"Class like behavior composition, but better","dist-tags":{"latest":"1.0.0"},"maintainers":[{"name":"gasteve","email":""}],"time":{"modified":"2026-04-10T21:48:04.000Z","created":"2013-07-03T01:45:12.944Z","1.0.0":"2013-07-03T01:45:12.944Z"},"users":{},"author":{"name":"Stephen Pair","email":"stephen@bitpay.com"},"repository":{"type":"git","url":"http://github.com/gasteve/classtool.git"},"versions":{"1.0.0":{"name":"classtool","description":"Class like behavior composition, but better","version":"1.0.0","author":{"name":"Stephen Pair","email":"stephen@bitpay.com"},"main":"./index","keywords":["class","behavior"],"repository":{"type":"git","url":"http://github.com/gasteve/classtool.git"},"scripts":{},"devDependencies":{},"license":"MIT","readmeFilename":"README.md","_id":"classtool@1.0.0","dist":{"shasum":"0750fe3af874fa2b620751e4f3521e903c47f8e5","size":3164,"noattachment":false,"key":"/classtool/-/classtool-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/classtool/download/classtool-1.0.0.tgz"},"_npmVersion":"1.1.65","_npmUser":{"name":"gasteve","email":"stephen@pairhome.net"},"maintainers":[{"name":"gasteve","email":""}],"directories":{},"publish_time":1372815912944,"_hasShrinkwrap":false,"_cnpm_publish_time":1372815912944,"_cnpmcore_publish_time":"2021-12-16T19:20:09.463Z"}},"readme":"Classtool\n=========\n\nThis is a simple tool to enable class like idioms in JavaScript.  It is notably different\nfrom traditional class based inheritance in the following ways:\n\n- inheritance structure is not part of the class definition\n- bindings to the outside are explicit (including binding to a superclass)\n- default bindings allow for easy class creation while preserving override capability\n\nThe following is an example class definition:\n\n    function ClassSpec(b) {\n      var fs = b.fs || require('fs'); // example of a binding\n   \n      function Class() {\n        // Body of constructor function\n      };\n      // Optional - Define a default (but overridable) superclass\n      Class.superclass = b.superclass || require('./superClass').class();   \n\n      Class.prototype.methodA = function() {\n        // Body of method A\n      };\n   \n      Class.prototype.methodB = function() {\n        // Body of method B\n      };\n\n      return Class;\n    };\n    module.defineClass(ClassSpec); \n\nTo use classtool, simply require it at the beginning of your program:\n\n    require('classtool');\n\nThere are two ways to instantiate the class in client code:\n\n    var MyClass = require('./path/to/classfile').class();\n    var MyClass = require('./path/to/classfile').createClass({fs: mockFileSystem});\n\nIn the first example, each call will return the same class instance (the 'default' \nclass instance).  In the second example, each call returns a new class instance.  The \nsecond call also shows how you would override the default bindings (passing in an \nobject meant to mimic the file system in this example). \n\nClass instances can be registered in a dictionary of named classes as follows:\n\n    var MyClassForTesting = require('./classfile').createClass('testing', {fs: mockFileSystem});\n    var MyRealClass = require('./classfile').createClass('real', {fs: require('fs')});\n\nYou can later reference the same class instances as follows:\n\n    var MyClassForTesting = require('./classfile').class('testing');\n    var MyRealClass = require('./classfile').class('real');\n\nIf the name is omitted, \"default\" is used.  The following expressions are equivalent:\n\n    var MyClass = require('./classfile').class();\n    var MyClass = require('./classfile').class('default');\n\nTo create an inheritance chain, use the method inherit() as follows:\n\n    MyClass.inherit(MySuperClass);\n    MyClass.inherit(MySuper, MySuperSuper, MySuperDeDuper);\n\nTo create instances of your class, do the following:\n\n    new MyClass();\n\nFor convenience, the \"new\" method is exported to allow instantiation:\n\n    var myInstance = require('./myClass').new();\n\nThis form is equivalent to:\n\n    var MyClass = require('./myClass').class();\n    var myInstance = new MyClass();\n\nYou may also instantiate instances of a specific class as follows:\n\n    var myTestInstance = require('./myClass').new('test');\n\nIt's also possible to explicitly invoke methods of a superclass.  Invoke the superclass \nconstructor as follows:\n\n    function Class() {\n      Class.super(this, arguments);\n    };\n\nInvoke any normal method in the superclass as follows:\n\n    Class.prototype.methodA = function() {\n      Class.super(this, 'methodA', arguments);\n    };\n\n","_attachments":{},"readmeFilename":"README.md","license":"MIT"}