{"id":34650401,"url":"https://github.com/roaatech/js-simple-oop","last_synced_at":"2026-05-22T23:03:40.745Z","repository":{"id":57283626,"uuid":"56236507","full_name":"roaatech/js-simple-oop","owner":"roaatech","description":"Simple OOP inheritance implementation for JavaScript","archived":false,"fork":false,"pushed_at":"2016-08-11T08:44:08.000Z","size":8,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-05-16T09:29:33.747Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/roaatech.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-04-14T12:44:15.000Z","updated_at":"2016-04-14T16:02:37.000Z","dependencies_parsed_at":"2022-08-26T13:30:18.149Z","dependency_job_id":null,"html_url":"https://github.com/roaatech/js-simple-oop","commit_stats":null,"previous_names":["itvisionsy/js-simple-oop"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/roaatech/js-simple-oop","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/roaatech%2Fjs-simple-oop","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/roaatech%2Fjs-simple-oop/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/roaatech%2Fjs-simple-oop/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/roaatech%2Fjs-simple-oop/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/roaatech","download_url":"https://codeload.github.com/roaatech/js-simple-oop/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/roaatech%2Fjs-simple-oop/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33376007,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-22T21:56:13.512Z","status":"ssl_error","status_checked_at":"2026-05-22T21:56:10.769Z","response_time":265,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":"2025-12-24T17:55:38.341Z","updated_at":"2026-05-22T23:03:40.740Z","avatar_url":"https://github.com/roaatech.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# js-simple-oop\nSimple OOP inheritance implementation for JavaScript.\n\nIt is trying to minimize any conventions and rules on how to write your JS code.\n So, you will keep writing your JS code as you used to. That includes: defining\n classes, defining private and public methods, ....\n\n_Only one_ convention (which is originally a JavaScript one) to mention: Add\nmethods in a named way, so try to avoid writing any anonymous/closure method\nwithout name. i.e. instead of writing `function(param1, param2){ ... }` add a\nname so it will become `function someName(param1, param2){ ... }` and that will\nwork exactly without any effects on your code and execution.\n\n## Install\n```\nnpm install js-simple-oop\n```\n\n## How to use\n\n### Include the module\n```JavaScript\nvar OOP = require('js-simple-oop');\n```\n\n### Creating classes\nYou can create a class by calling the `extendClass` method on OOP base class or\n any extended subclass.\n\n```JavaScript\n\n// Creating LivingCreature class as the main class with a constructor\nvar LivingCreature = OOP.extendClass(function(age){\n  this.age = age;\n});\n\n// Creating IntelligentCreature extending LivingCreature without a constructor\n// so LivingCreature constructor will be used\nvar IntelligentCreature = LivingCreature.extendClass();\n\n//Creating Human extending IntelligentCreature, and extending the LivingCreature constructor\nvar Human = IntelligentCreature.extendClass(function(name, age){\n  this.parentConstructor(age); //calls parent method\n  this.name = name;\n});\n```\n\nExtended subclasses will receive the following class-level methods:\n 1. `.extendClass(subClass)` which allows to create subclasses from the current.\n 1. `.defineMethod(method[, name])` which allows to define new named methods\n 1. `.defineProperty(property[, getter[, setter[, descriptors]]])` which allows\n   to define a property. Check [Mozilla Developer Network](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty)\n   for info.\n\nAlso, in the base OOP class, you can use following methods:\n 1. `OOP.extendClass(Class)` allows to create new main classes.\n 1. `OOP.extend(SubClass, MainClass)` to inherit MainClass to SubClass.\n\n### Adding methods\n\nYou can add methods in the normal JavaScript way using the prototype.\nPlease note it is preferred to use the named functions when defining methods.\n```JavaScript\n//this way\nLivingCreature.prototype.identify = function identify(){\n  //...\n};\n\n//is preferred to this way\nLivingCreature.prototype.identify = function(){\n  //...\n};\n```\n\nOr you can use the added `.defineMethod` method which will exactly the same result\n```JavaScript\n//this way\nIntelligentCreature.defineMethod(function identify(){\n  console.log('I am an intelligent creature.');\n  //One way to call parent overridden methods, thanks to named methods, which made\n  //this one possible.\n  return this.propagateCall();\n});\n\n//is preferred to this way\nIntelligentCreature.defineMethod(function(){\n  //...\n}, 'identify');\n```\n\n### Calling overridden methods\nIn subclasses, you can override an inherited method by define a method with the\nsame name.\nTo call the overridden method from within the overriding one, you can either\nuse the `this.parentMethod(methodName[, params...])` or the shorthand\n`this.propagateCall([params...])` which will detect the name of the calling\nmethod and call the first method internally.\n```JavaScript\nLivingCreature.defineMethod(function identify(){\n  console.log('I am a living creature!');\n});\n\nIntelligentCreature.defineMethod(function identify(){\n  this.parentMethod('identify');\n  console.log('Also, I am an intelligent creature!');\n});\n\nHuman.defineMethod(function identify(){\n  this.propagateCall();\n  console.log('And guess what? I am human....');\n});\n\nvar someone = new Human();\nsomeone.identify();\n\n//result will be:\n//I am a living creature!\n//Also, I am an intelligent creature!\n//And guess what? I am human....\n\n```\n\nPlease note that calling overridden methods this way requires that methods were\ndefined in the named way.\n\nIf you are not happy with the named method definitions, you can still use the\noriginal JavaScript method calling:\n```JavaScript\nLivingCreature.prototype.idenfity = function(){\n  console.log('I am a living creature!');\n};\n\nIntelligentCreature.prototype.identify= function(){\n  this.__proto__.__proto__.identify();\n  console.log('Also, I am an intelligent creature!');\n};\n```\n\nIf you will go with this traditional approach, please note that the position of\nthe overridden method to be called is relative to the calling object, not calling class.\n\n### Creating and using objects\nNothing new here. It is the normal `new` keyword.\n\n```JavaScript\nvar tree = new LivingCreature();\nvar dolphin = new IntelligentCreature(12);\nvar person1 = new Human('Muhammad', 20);\nvar person2 = new Human('Salim', 47);\n```\n\n## Sample\nPlease check the [sample](sample.js) file which includes a nice example.\n\n## Author\nMuhannad Shelleh \u003cmuhannad.shelleh@live.com\u003e\n\n## License\nPublished under the [MIT](LICENSE) license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Froaatech%2Fjs-simple-oop","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Froaatech%2Fjs-simple-oop","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Froaatech%2Fjs-simple-oop/lists"}