{"id":17030191,"url":"https://github.com/rob-blackbourn/example-operator-overloading","last_synced_at":"2026-02-07T17:31:12.488Z","repository":{"id":42766412,"uuid":"277115741","full_name":"rob-blackbourn/example-operator-overloading","owner":"rob-blackbourn","description":"An example using @jetblack/operator-overloading","archived":false,"fork":false,"pushed_at":"2023-03-05T04:02:43.000Z","size":353,"stargazers_count":2,"open_issues_count":3,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-14T10:32:08.327Z","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/rob-blackbourn.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":"2020-07-04T13:32:11.000Z","updated_at":"2021-10-22T05:31:21.000Z","dependencies_parsed_at":"2025-02-11T23:35:15.345Z","dependency_job_id":"8688fbd3-512b-49d6-9356-932c80fca6e5","html_url":"https://github.com/rob-blackbourn/example-operator-overloading","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/rob-blackbourn/example-operator-overloading","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rob-blackbourn%2Fexample-operator-overloading","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rob-blackbourn%2Fexample-operator-overloading/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rob-blackbourn%2Fexample-operator-overloading/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rob-blackbourn%2Fexample-operator-overloading/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rob-blackbourn","download_url":"https://codeload.github.com/rob-blackbourn/example-operator-overloading/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rob-blackbourn%2Fexample-operator-overloading/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29201072,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-07T16:28:23.579Z","status":"ssl_error","status_checked_at":"2026-02-07T16:28:22.566Z","response_time":63,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: 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":"2024-10-14T08:04:57.606Z","updated_at":"2026-02-07T17:31:12.468Z","avatar_url":"https://github.com/rob-blackbourn.png","language":"JavaScript","readme":"# example-operator-overloading\n\nThis project demonstrates how to use [@jetblack/operator-overloading](https://github.com/rob-blackbourn/jetblack-operator-overloading).\n\n## Usage\n\n```bash\nnpm install\nnpm start\n```\n\n## Installation\n\nYou can add the plugin to your project by adding the npm package.\n\n```bash\nnpm install --save-dev @jetblack/operator-overloading\n```\n\nThe babel file will look something like this.\n\n```json\n{\n  \"presets\": [\n      [\n        \"@babel/preset-env\",\n        {\n          \"targets\": {\n            \"node\": \"current\"\n          }\n        }\n      ]\n  ],\n  \"plugins\": [\"module:@jetblack/operator-overloading\"]\n}\n```\n\n## The code\n\nHere is the code. We need to enable the overloading with the `'operator-overloading enabled'`\nstatement.\n\n```javascript\n'operator-overloading enabled'\n\nclass Point {\n\n  constructor(x, y) {\n      this.x = x\n      this.y = y\n  }\n  \n  [Symbol.for('+')](other) {\n      const x = this.x + other.x\n      const y = this.y + other.y\n      return new Point(x, y)\n  }\n}\n\n// Check primitives still work\nconst i1 = 3\nconst i2 = 4\nconst i3 = i1 + i2\nconsole.log(i3)\n\n// Check overloads work\nconst p1 = new Point(5, 5)\nconst p2 = new Point(2, 3)\nconst p3 = p1 + p2\nconsole.log(p3)\n\n// What happens with nulls?\nconst s1 = null\nconst s2 = 'hello'\nconst s3 = s1 + s2\nconsole.log(s3)\n\nconsole.log('Done')\n```\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frob-blackbourn%2Fexample-operator-overloading","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frob-blackbourn%2Fexample-operator-overloading","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frob-blackbourn%2Fexample-operator-overloading/lists"}