{"id":18256015,"url":"https://github.com/ull-esit-pl/callable-objects","last_synced_at":"2025-07-23T02:35:32.355Z","repository":{"id":228824976,"uuid":"775018525","full_name":"ULL-ESIT-PL/callable-objects","owner":"ULL-ESIT-PL","description":"Callable Objects in JS","archived":false,"fork":false,"pushed_at":"2025-03-19T12:05:51.000Z","size":8,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-08T22:29:55.933Z","etag":null,"topics":["callables"],"latest_commit_sha":null,"homepage":"https://apuntes-pl.vercel.app/topics/language-design/callables","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/ULL-ESIT-PL.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-03-20T16:03:13.000Z","updated_at":"2025-03-19T12:09:29.000Z","dependencies_parsed_at":"2024-03-20T17:31:36.356Z","dependency_job_id":"ebc5f9a3-2201-4911-8a08-cb53f43af34e","html_url":"https://github.com/ULL-ESIT-PL/callable-objects","commit_stats":null,"previous_names":["ull-esit-pl/callable-objects"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ULL-ESIT-PL/callable-objects","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ULL-ESIT-PL%2Fcallable-objects","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ULL-ESIT-PL%2Fcallable-objects/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ULL-ESIT-PL%2Fcallable-objects/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ULL-ESIT-PL%2Fcallable-objects/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ULL-ESIT-PL","download_url":"https://codeload.github.com/ULL-ESIT-PL/callable-objects/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ULL-ESIT-PL%2Fcallable-objects/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266606904,"owners_count":23955365,"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","status":"online","status_checked_at":"2025-07-23T02:00:09.312Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"robots_txt_url":"https://github.com/robots.txt","online":true,"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":["callables"],"created_at":"2024-11-05T10:19:26.753Z","updated_at":"2025-07-23T02:35:32.301Z","avatar_url":"https://github.com/ULL-ESIT-PL.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Creating Callable Objects in JavaScript\n\nA callable object is a data structure that behaves as both an object and a function. \n\nYou can \n\n- access and assign properties `obj.bar`, \n- call methods `obj.foo()`, but also \n- call the object directly `obj()`, as if it were a function.\n\nThe direct call is like calling a method of obj which has access to the object’s properties through its this context.\n\nCallable Objects can also be thought of as **stateful functions**. \nFunctions are inherently single instance, stateless procedures. \nCallable Objects are instantiated, stateful procedures.\n\nSee package [callable-object](https://www.npmjs.com/package/callable-object) for a simple implementation of a callable object in JavaScript. See also the example at [callable-instance.js](callable-instance.js).\n\n## Goal\n\nWe want to create a Class/constructor that we can use to create callable objects that redirect their calls to a method named `_call`. \n\nWe want this redirect so that we can inherit from our Class and easily override and extend the `_call` method with new functionality, \nwithout having to worry about the inner workings of the callable object.\n\nTo do this, we’re going to need to \ninherit from the `Function` constructor, \nwhich inherits from `Object`, and \nallows us to create both an object and a dynamic function.\n\n*Our main hurdle is giving a function object a reference to itself*.\n\nIn order to have a reference to the `_call` method, \nthe function part of our function object, generated by our `Callable` class/constructor, must have a reference to itself.\n\n## The Solutions\n\nWe want to create an extensible `Callable` class that \nmaintains proper and correct inheritance in JavaScript, and \nallows us to call the objects it constructs as functions, with a reference to themselves, \nredirecting those calls to an overridable method _call.\n\n## References\n\n1. [Creating Callable Objects in JavaScript](https://medium.com/@adrien.za/creating-callable-objects-in-javascript-fbf88db9904c) by Adrien. 2019.\n2. [gist](https://gist.githubusercontent.com/arccoza/d6209b4c7317a22f0e929808640b40a5/raw/2e99d608329a75c17c38b6d4285492520c968a75/index.js)\n3. [repl.it](https://replit.com/@arccoza/Javascript-Callable-Object-using-bind#index.js)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Full-esit-pl%2Fcallable-objects","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Full-esit-pl%2Fcallable-objects","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Full-esit-pl%2Fcallable-objects/lists"}