{"id":20098842,"url":"https://github.com/mark-5/roles-js","last_synced_at":"2025-08-04T12:10:34.690Z","repository":{"id":22756412,"uuid":"26101951","full_name":"mark-5/roles-js","owner":"mark-5","description":"Role::Tiny roles for JavaScript","archived":false,"fork":false,"pushed_at":"2014-11-16T01:22:37.000Z","size":256,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-02T16:48:20.379Z","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/mark-5.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-11-03T03:14:44.000Z","updated_at":"2015-09-01T15:30:56.000Z","dependencies_parsed_at":"2022-08-21T10:31:23.679Z","dependency_job_id":null,"html_url":"https://github.com/mark-5/roles-js","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/mark-5/roles-js","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mark-5%2Froles-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mark-5%2Froles-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mark-5%2Froles-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mark-5%2Froles-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mark-5","download_url":"https://codeload.github.com/mark-5/roles-js/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mark-5%2Froles-js/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268694697,"owners_count":24291854,"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-08-04T02:00:09.867Z","response_time":79,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","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":[],"created_at":"2024-11-13T17:06:53.920Z","updated_at":"2025-08-04T12:10:34.617Z","avatar_url":"https://github.com/mark-5.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Roles.js\n\nRoles.js is a javscript library for [Role::Tiny](https://metacpan.org/pod/Role::Tiny) inspired traits. This includes support for providing methods, requiring methods, detecting conflicting methods, and installing method modifiers.\n\n```\n    var HasFoo = new Role({\n        get_foo: function(){ ... },\n    }, {\n        after: {initialize: function(){ ... }},\n        before: {render: function(){ ... }}\n    });\n    var View = Backbone.View.extend({ ... });\n    var ViewWithFoo = Role.apply_roles(View, HasFoo);\n```\n\n## Class Methods\n\n### new(methods, modifiers)\n\nThe constructor to instantiate roles.\n\n```\nvar MyRole = new Role({my_method: function(){ ... }}, {with: AnotherRole});\n```\n\n#### methods\n\nAn object containing methods the role provides.\n\n#### modifiers\n\nThis is an object containing Role::Tiny keywords - with, requires, before, around, after. with and requires can be keyed to either a single role/method name, or an array of roles/methods. Method modifiers are objects with method name keys, and modifier code values.\n\n```\n{\n    with: [Roles...],\n    requires: [method_names...],\n    before: {method: function(){ ... } },\n    around: {method: function(original, arg1, arg2) { ... original.call(this, arg1, arg2) ... }},\n    after: {method: function(){ ... }},\n}\n```\n\n### apply_roles(Class, ...)\n\nThe main entry point to Roles.js. Returns a copy of the given class, with the specified roles applied.\n\n```\nvar ClassWithRoles = Role.apply_roles(Class, FirstRole, SecondRole);\n```\n\n### is_role(MaybeRole)\n\n\n### does_role(RoleOrClass)\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmark-5%2Froles-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmark-5%2Froles-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmark-5%2Froles-js/lists"}