{"id":20514233,"url":"https://github.com/webreflection/classtrophobic","last_synced_at":"2025-04-14T00:11:29.109Z","repository":{"id":65993121,"uuid":"78932697","full_name":"WebReflection/classtrophobic","owner":"WebReflection","description":"Breaking JS Class Constrains","archived":false,"fork":false,"pushed_at":"2017-01-16T19:43:59.000Z","size":2005,"stargazers_count":43,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-27T14:12:47.320Z","etag":null,"topics":["babel","basic","class","extend","native"],"latest_commit_sha":null,"homepage":"","language":"HTML","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/WebReflection.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2017-01-14T10:02:19.000Z","updated_at":"2024-12-01T19:56:36.000Z","dependencies_parsed_at":"2024-02-01T17:48:14.884Z","dependency_job_id":null,"html_url":"https://github.com/WebReflection/classtrophobic","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WebReflection%2Fclasstrophobic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WebReflection%2Fclasstrophobic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WebReflection%2Fclasstrophobic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WebReflection%2Fclasstrophobic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/WebReflection","download_url":"https://codeload.github.com/WebReflection/classtrophobic/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248799956,"owners_count":21163404,"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":["babel","basic","class","extend","native"],"created_at":"2024-11-15T21:15:27.497Z","updated_at":"2025-04-14T00:11:29.086Z","avatar_url":"https://github.com/WebReflection.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Classtrophobic [![build status](https://secure.travis-ci.org/WebReflection/classtrophobic.svg)](http://travis-ci.org/WebReflection/classtrophobic) [![Coverage Status](https://coveralls.io/repos/github/WebReflection/classtrophobic/badge.svg?branch=master)](https://coveralls.io/github/WebReflection/classtrophobic?branch=master)\n\nZero Runtime, Babel Proof, Classes.\n\n```js\nconst Class = require('classtrophobic');\n\nconst List = Class({\n  extends: Array,         // class extends Array {}\n  constructor(...args) {  // super();\n    this.super();\n    this.push(...args);\n  },\n  push(...args) {         // super.push(...args);\n    this.super.push(...args);\n    return this;\n  }\n});\n```\n\n### Don't Miss [The Related Post](https://medium.com/@WebReflection/a-case-for-js-classes-without-classes-9e60b3b5992#.oh0mweilj)\nIf you want to know more about this project use cases, and also why it was born in the first place,\n[read the story in Medium](https://medium.com/@WebReflection/a-case-for-js-classes-without-classes-9e60b3b5992#.oh0mweilj).\n\n\n### Classtrophobic on ES5\nUsing some extra runtime, avoiding the usage of `class` and `Proxy`,\n[Classtrophobic for ES5](https://github.com/WebReflection/classtrophobic-es5) works for all Mobile browsers, and IE11+ for Desktop.\n\n\n### Which Version For My Targets?\n\nYou can test live both [classtrophobic](https://webreflection.github.io/classtrophobic/test.html) and [classtrophobic-es5](https://webreflection.github.io/classtrophobic-es5/test.html).\nIf the page turns out green, you're good to go!\n\nThe main difference is that ES5 version has a greedy runtime when it comes to `super` usage,\nwhile this original version uses real classes and delegate to Proxy access the `super` resolution,\nworking only when a method is accessed and per single method, as opposite of runtime setup for all methods in the es5 case.\n\n\u003csup\u003e\u003csub\u003eLuckily overrides are not the most frequent thing ever.\u003c/sub\u003e\u003c/sup\u003e\n\n\n### Ready for Refactory\nSemantics used in native ES6 classes are equivalent in Classtrophobic.\n\n```js\n// Native Class\nclass PushChainable extends Array {\n  static size(arr) {\n    return arr.length;\n  }\n  constructor(...args) {\n    super().push(...args);\n  }\n  push(...args) {\n    super.push(...args);\n    return this;\n  }\n}\n\n// Classtrophobic\nconst PushChainable = Class({\n  extends: Array,\n  static: {size:(arr) =\u003e arr.length},\n  constructor(...args) {\n    this.super().push(...args);\n  },\n  push(...args) {\n    this.super.push(...args);\n    return this;\n  }\n});\n```\n\nFeel free to compare transpiled output for both [native](http://babeljs.io/repl/#?babili=false\u0026evaluate=true\u0026lineWrap=false\u0026presets=es2015\u0026experimental=false\u0026loose=false\u0026spec=false\u0026code=class%20PushChainable%20extends%20Array%20%7B%0A%20%20static%20size(arr)%20%7B%0A%20%20%20%20return%20arr.length%3B%0A%20%20%7D%0A%20%20constructor(...args)%20%7B%0A%20%20%20%20super().push(...args)%3B%0A%20%20%7D%0A%20%20push(...args)%20%7B%0A%20%20%20%20super.push(...args)%3B%0A%20%20%20%20return%20this%3B%0A%20%20%7D%0A%7D\u0026playground=true) and [classtrophobic](http://babeljs.io/repl/#?babili=false\u0026evaluate=true\u0026lineWrap=false\u0026presets=es2015\u0026experimental=false\u0026loose=false\u0026spec=false\u0026code=const%20PushChainable%20%3D%20Class(%7B%0A%20%20extends%3A%20Array%2C%0A%20%20static%3A%20%7Bsize%3A(arr)%20%3D%3E%20arr.length%7D%2C%0A%20%20constructor(...args)%20%7B%0A%20%20%20%20this.super().push(...args)%3B%0A%20%20%7D%2C%0A%20%20push(...args)%20%7B%0A%20%20%20%20this.super.push(...args)%3B%0A%20%20%20%20return%20this%3B%0A%20%20%7D%0A%7D)%3B\u0026playground=true), considering each method that will use `super`, in the transpiled case, will be polluted with similar logic, inevitably increasing the final project size to deliver.\n\nWith Classtrophobic, the total amount of extra needed bytes is around 800 [minified](classtrophobic.min.js) and gzipped.\nThat's going to be the only extra code that will ever be needed to execute your classes,\nwhich is represented by [100 well indented LOC](classtrophobic.js) in total.\n\n\n\n## What Does Classtrophobic That Others Don't?\nTo start with, it uses native `class`, because there's more than just prototypal inheritance in ES2015 classes.\nAs example, if you subclass an `Array` with good old JS, you'll lose your class as soon as you'll call a method.\n\n```js\nfunction List() {}\nObject.setPrototypeOf(List, Array);\nObject.setPrototypeOf(List.prototype, Array.prototype);\n\n(new List).slice() instanceof List; // ⚠️️ false\n\n// even defining Symbol.species at runtime\nObject.defineProperty(List, Symbol.species, {get:()=\u003eList});\n\n(new List).slice() instanceof List; // ⚠️️ still false\n```\n\nSo while [es-class](https://github.com/WebReflection/es-class) and similar libraries can grant support for very old browsers,\nClasstrophobic needs no transpilation at its core and requires browsers natively compatible with classes.\n\nIn order to have a robust and fast `super` mechanism that perfectly simulate its native counter part,\nClasstrophobic also needs an engine that is compatible with [Proxy](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Proxy).\n\nDon't worry though, if you don't need `super` access, your code would run without needing a Proxy at all.\n\n\n\n## Compatibility\n\nIf your engine is compatible with [ES2015 class](http://caniuse.com/#feat=es6-class), you can already use this tiny library.\nHowever, if your code needs `super` calls, be sure [ES2015 Proxy](http://caniuse.com/#feat=proxy) is available too.\n\n\n\n## License\n\n```\nCopyright (C) 2017 by Andrea Giammarchi - @WebReflection\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebreflection%2Fclasstrophobic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwebreflection%2Fclasstrophobic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebreflection%2Fclasstrophobic/lists"}