{"_id":"arale","_rev":"9-e05d37dff26a9fc7449f1bda848b3f9e","name":"arale","description":"Arale Class and Events","dist-tags":{"latest":"0.2.0"},"versions":{"0.1.0":{"name":"arale","version":"0.1.0","description":"Arale is a basic tools","dependencies":{},"devDependencies":{},"scripts":{},"readme":"# Arale tools for node\n\n------------------------\n\nhttp://aralejs.org\n","readmeFilename":"README.md","_id":"arale@0.1.0","dist":{"shasum":"48f0a1a5538b26d36b9d2775580c22d520dc3368","tarball":"https://registry.npmjs.org/arale/-/arale-0.1.0.tgz","integrity":"sha512-RnZOKUvHScac6d69MmnCsz3k6dDYny20IA4/WH/Msv4SpgJvOwPKIdJ/EUVbXDmnrYSdDXFvBkIv30s10uNEFQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCPjpCO1U/a0p7XBoStHgXCg0xqSjQwYnvd8EIZoN+jYwIgfCxOtjS6fyhpTLPOr9c5O9kKxoyh56QSvo0mzd75IY0="}]},"_npmVersion":"1.1.65","_npmUser":{"name":"lepture","email":"sopheryoung@gmail.com"},"maintainers":[{"name":"lepture","email":"sopheryoung@gmail.com"}]},"0.2.0":{"name":"arale","version":"0.2.0","description":"Arale Class and Events","author":{"name":"Arale Team","email":"aralejs@googlegroups.com"},"keywords":["class","events","OOP"],"dependencies":{},"devDependencies":{"mocha":"*","expect.js":">=0.2.0"},"repository":{"type":"git","url":"https://github.com/lepture/arale.git"},"scripts":{"test":"make test"},"readme":"# Arale\n\nThis is a fork of [arale.class](http://aralejs.org/class/) and [arale.events](http://aralejs.org/events/). The core of arale projects.\n\n-----------------\n\n[![Build Status](https://travis-ci.org/lepture/arale.png?branch=master)](https://travis-ci.org/lepture/arale)\n\nThe Class and Events of [Arale](http://aralejs.org/) is very easy to use, and stable now. Test cases with [97% coverage](http://lab.lepture.com/arale/coverage), and you don't have to worry about the 3% left.\n\n\n## Class\n\nRead it in Chinese at [Arale.Class](http://aralejs.org/class/).\n\n\n### create\n\n`Class.create([parent], [properties])` create a new class:\n\n```javascript\n/* pig.js */\nvar Class = require('arale').Class;\n\nvar Pig = Class.create({\n    initialize: function(name) {\n        this.name = name;\n    },\n\n    talk: function() {\n        console.log('I am' + this.name);\n    }\n});\n\nmodule.exports = Pig;\n```\n\n### extend\n\nEvery class created by `Class.create` has an `extend` method:\n\n```javascript\n/* red-pig.js */\nvar Pig = require('./pig');\n\nvar RedPig = Pig.extend({\n    initialize: function(name) {\n        RedPig.superclass.initialize.call(this, name);\n    },\n\n    color: 'red'\n});\n\nmodule.exports = RedPig;\n```\n\n### implement\n\nYou can also mixin other classes:\n\n```javascript\n/* flyable.js */\nexports.fly = function() {\n    console.log('I am flying');\n};\n```\n\n```javascript\n/* flyable-red-pig.js */\nvar RedPig = require('./red-pig');\nvar Flyable = require('./flyable');\n\nvar FlyableRedPig = RedPig.extend({\n    Implements: Flyable,\n\n    initialize: function(name) {\n        FlyableRedPig.superclass.initialize.call(this, name);\n    }\n});\n\nmodule.exports = FlyableRedPig;\n```\n\nThe other way of mixin:\n\n```javascript\n/* flyable-red-pig-extension.js */\nvar FlyableRedPig = require('./flyable-red-pig');\n\nFlyableRedPig.implement({\n   swim: function() {\n       console.log('I can swim');\n   }\n});\n```\n\n### Class\n\nTransfrom a function to class:\n\n```javascript\nfunction Animal() {\n}\nAnimal.prototype.talk = function() {};\n\nvar Dog = Class(Animal).extend({\n    swim: function() {}\n});\n```\n\n## Events\n\nRead it in Chinese at [Arale.Events](http://aralejs.org/events/).\n\n### How to\n\nThere are two ways of implementing events:\n\n```javascript\nvar Events = require('arale').Events;\n\nvar object = new Events();\nobject.on('expand', function() {\n    console.log('expanded');\n});\n\nobject.trigger('expand');\n```\n\nThe other way:\n\n```javascript\nvar Events = require('arale').Events;\n\nfunction Dog() {\n}\nEvents.mixTo(Dog);\n\nDog.prototype.sleep = function() {\n    this.trigger('sleep');\n};\n\nvar dog = new Dog();\ndog.on('sleep', function() {\n    console.log('the dog is sleeping');\n});\n\ndog.sleep();\n```\n\n### on\n\n`object.on(event, callback, [context])`\n\nYou can pass a context to change the **this**.\n\n```javascript\npost.on('saved', callback, that);\n```\n\nThere is an ``all`` event:\n\n```javascript\nproxy.on('all', function(eventName) {\n    object.trigger(eventName);\n});\n```\n\n### off\n\n`object.off([event], [callback], [context])`\n\n```javascript\n// remove the onChange callback of change event\nobject.off('change', onChange);\n\n// remove all callbacks of change event\nobject.off('change');\n\n// remove all onChange callbacks of every event\nobject.off(null, onChange);\n\n// remove all events for the context\nobject.off(null, null, context);\n\n// remove all events of the object\nobject.off();\n```\n\n\n### trigger\n\n`object.trigger(event, [*args])`\n\n```javascript\nvar obj = new Events();\n\nobj.on('x y', fn);\n\n// equals:\nobj.on('x').on('y');\n```\n","readmeFilename":"README.md","_id":"arale@0.2.0","dist":{"shasum":"a84d19fd0bc0e1ee21e87462eb171625e8b04fed","tarball":"https://registry.npmjs.org/arale/-/arale-0.2.0.tgz","integrity":"sha512-p+gAFbnX1kXklMKSPAldJgX+VjCcHfLu7sgglHe5zBV6NeH39tZNGMDB20msPFYwx9M0aYGzY/8fq8acDE3o+w==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIGy0fDWEeR/gEOFGNZDrDibwi0nRBEoY0IPIOmDc151jAiEA3WrrQoFJgLlTtPb6DVEPtb9o5SFSYjKSOa1CJ64bh28="}]},"_npmVersion":"1.1.66","_npmUser":{"name":"lepture","email":"lepture@me.com"},"maintainers":[{"name":"lepture","email":"sopheryoung@gmail.com"},{"name":"lifesinger","email":"lifesinger@gmail.com"},{"name":"popomore","email":"sakura9515@gmail.com"}]}},"readme":"# Arale tools for node\n\n------------------------\n\nhttp://aralejs.org\n","maintainers":[{"name":"lepture","email":"sopheryoung@gmail.com"},{"name":"lifesinger","email":"lifesinger@gmail.com"},{"name":"popomore","email":"sakura9515@gmail.com"}],"time":{"modified":"2022-06-13T03:20:44.250Z","created":"2012-12-08T15:04:40.666Z","0.1.0":"2012-12-08T15:04:46.823Z","0.2.0":"2012-12-19T10:04:29.375Z"},"author":{"name":"Arale Team","email":"aralejs@googlegroups.com"},"repository":{"type":"git","url":"https://github.com/lepture/arale.git"}}