{"id":17061606,"url":"https://github.com/paxa/classy","last_synced_at":"2026-04-28T20:40:03.840Z","repository":{"id":21586374,"uuid":"24906409","full_name":"Paxa/classy","owner":"Paxa","description":null,"archived":false,"fork":false,"pushed_at":"2015-01-21T05:36:35.000Z","size":196,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-28T15:16:19.584Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Paxa.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-10-07T18:55:08.000Z","updated_at":"2015-01-21T05:36:37.000Z","dependencies_parsed_at":"2022-08-21T20:20:49.066Z","dependency_job_id":null,"html_url":"https://github.com/Paxa/classy","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Paxa%2Fclassy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Paxa%2Fclassy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Paxa%2Fclassy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Paxa%2Fclassy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Paxa","download_url":"https://codeload.github.com/Paxa/classy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245074394,"owners_count":20556749,"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-10-14T10:47:35.895Z","updated_at":"2026-04-28T20:40:03.719Z","avatar_url":"https://github.com/Paxa.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://drone.io/bitbucket.org/paxa/classy/status.png)](https://drone.io/bitbucket.org/paxa/classy/latest)\r\n\r\n# Classy #\r\n\r\n## `'classy/object_extras'`\r\n\r\nUtility functions to have a better touch with objects:\r\n\r\n```js\r\nvar ObjectKit = require('classy/object_extras');\r\nObjectKit.extendGlobal();\r\n\r\n```\r\n\r\n**`extendGlobal`**\r\n\r\nextend global variable `Object`\r\n\r\n```js\r\nObjectKit.extendGlobal();\r\n```\r\n\r\n```js\r\n// iterates object\r\nObject.forEach(obj, function (key, value) {\r\n\r\n});\r\n\r\n// get values as array\r\nvar obj = {type: 'animal', wear: 'wool', lives: 9};\r\nObject.values(obj) // =\u003e ['animal', 'wool', 9];\r\n\r\n// more detail type of object\r\nObject.realType(null) // =\u003e 'null'\r\nObject.realType(new Date) // =\u003e 'date'\r\nObject.realType([]) // =\u003e 'array'\r\n\r\n// methods of object\r\nObject.methods(obj);\r\n\r\n// own properties\r\nObject.properties(obj) // -\u003e return own properties\r\n\r\n// all properties of object\r\nObject.allProperties(obj) // -\u003e return all properties of object\r\n\r\n// variables\r\nObject.instance_variables(obj)\r\n\r\n// array of instance variable names\r\nObject.instance_variable_names(obj)\r\n\r\n// same as ruby's ancestors\r\nObject.ancestors(obj) // return array of inherited prototypes\r\n\r\n// check if object is constructor\r\nObject.isConstructor(obj);\r\n\r\n```\r\n\r\nRuby like classes for Node.js\r\n\r\n### Api example\r\n\r\n```js\r\nvar Animal = {\r\n  isAnimal: true,\r\n\r\n};\r\n\r\nvar Cat = Classy.build('Cat', function (proto, mutator) {\r\n  this.extend(Animal);\r\n\r\n  proto.initialize = function() {\r\n    this.birthtime = new Date;\r\n  };\r\n\r\n  mutator.getter(proto, 'age', function() {\r\n    return new Date() - this.birthtime;\r\n  });\r\n\r\n  mutator.aliasProperty(proto, 'new_age', 'age');\r\n\r\n  ['left', 'right'].forEach(function(side) {\r\n    proto[side + 'Hand'] = side + \" hand\";\r\n  });\r\n});\r\n\r\nCat.classEval(function(proto) {\r\n  proto.tailMode = \"down\";\r\n\r\n  proto.tailUp = function () {\r\n    this.tailMode = \"up\";\r\n  };\r\n\r\n  proto.tailDown = function () {\r\n    this.tailMode = \"down\";\r\n  };\r\n\r\n  proto.moveTail = function() {\r\n    this.tailMode = this.tailMode == \"up\" ? \"down\" : \"up\"\r\n  }\r\n});\r\n\r\nvar aCat = new Cat;\r\n\r\nconsole.log('klassName', aCat.klassName);\r\nconsole.log('instance_variables', aCat.instance_variables);\r\nconsole.log('object_id', aCat.object_id);\r\nconsole.log('object_id', (new Cat).object_id);\r\nconsole.log('ancestors', Cat.ancestors);\r\nconsole.log('parentKlass', Cat.parentKlass);\r\nconsole.log('klass', aCat.klass);\r\nconsole.log('Class.klass', Cat.klass);\r\nconsole.log('is_a', aCat.is_a(aCat.klass));\r\nconsole.log('tap', aCat.tap(function() { console.dir(this); }));\r\nconsole.log('inspect', aCat.inspect());\r\nconsole.log('#age', aCat.age);\r\nconsole.log('#new_age', aCat.age);\r\n```\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpaxa%2Fclassy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpaxa%2Fclassy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpaxa%2Fclassy/lists"}