{"id":22985386,"url":"https://github.com/aj-dev/angular-base-class","last_synced_at":"2025-04-02T11:13:01.052Z","repository":{"id":26997309,"uuid":"30461269","full_name":"aj-dev/angular-base-class","owner":"aj-dev","description":"An AngularJS factory for simple class based inheritance with support for mixins","archived":false,"fork":false,"pushed_at":"2021-08-01T05:44:12.000Z","size":45,"stargazers_count":1,"open_issues_count":10,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-08T02:46:31.449Z","etag":null,"topics":["angularjs","base-class","inheritance","javascript","mixins"],"latest_commit_sha":null,"homepage":"","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/aj-dev.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":"2015-02-07T16:17:35.000Z","updated_at":"2017-02-07T22:33:06.000Z","dependencies_parsed_at":"2022-08-30T16:11:09.853Z","dependency_job_id":null,"html_url":"https://github.com/aj-dev/angular-base-class","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aj-dev%2Fangular-base-class","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aj-dev%2Fangular-base-class/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aj-dev%2Fangular-base-class/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aj-dev%2Fangular-base-class/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aj-dev","download_url":"https://codeload.github.com/aj-dev/angular-base-class/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246802627,"owners_count":20836373,"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":["angularjs","base-class","inheritance","javascript","mixins"],"created_at":"2024-12-15T03:31:49.245Z","updated_at":"2025-04-02T11:13:00.821Z","avatar_url":"https://github.com/aj-dev.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# angular-base-class\n[![Build Status](https://travis-ci.org/aj-dev/angular-base-class.svg?branch=master)](https://travis-ci.org/aj-dev/angular-base-class) [![Dependencies](https://david-dm.org/aj-dev/angular-base-class.svg)](https://david-dm.org/aj-dev/angular-base-class#info=dependencies\u0026view=table) [![DevDependencies](https://david-dm.org/aj-dev/angular-base-class/dev-status.svg)](https://david-dm.org/aj-dev/angular-base-class#info=devDependencies\u0026view=table) [![Coverage Status](https://coveralls.io/repos/aj-dev/angular-base-class/badge.svg)](https://coveralls.io/r/aj-dev/angular-base-class) [![npm](https://img.shields.io/npm/dm/angular-base-class.svg)](https://www.npmjs.com/package/angular-base-class)\n\nAn AngularJS factory for simple class based inheritance with support for mixins\n\n## Table of contents\n1. [Key features](#key-features)\n2. [Installation](#installation)\n3. [Usage](#usage)\n\t- [Default constructor](#default-constructor)\n\t- [Custom constructor](#custom-constructor)\n\t- [With mixins](#with-mixins)\n4. [Running tests](#running-tests)\n5. [Credits](#credits)\n6. [License](#license)\n\n## Key features\n- Constructor definition is optional\n- Uses ```this._super('methodName', arguments)``` to call super class methods\n- Supports multiple inheritance by resolving correct ```this``` context in ```super()``` calls\n- Mixins can be injected and used by adding them to ```mixins: []```\n- Does not override inherited mixins\n- Compatible with AngularJS 1.2.x - 1.6.x\n\n## Installation\n- npm\n\t- ```npm i angular-base-class --save```\n\t- include a reference to node_modules/angular-base-class/angular-base-class.js\n- bower\n\t- ```bower install angular-base-class --save```\n\t- include a reference to bower_components/angular-base-class/angular-base-class.js\n\n## Usage\n- Include angular-base-class.min.js in your project\n- Add module ```BaseClass``` as dependency to your AngularJS app\n\n##### Default constructor\n```js\nangular.module('App', ['BaseClass'])\n\t.factory('Mammal', ['BaseClass', function (BaseClass) {\n\t\treturn BaseClass.extend({\n\t\t\tsetAge: function (age) {\n\t\t\t\tthis.age = age;\n\t\t\t},\n\t\t\tgetAge: function () {\n\t\t\t\treturn this.age;\n\t\t\t}\n\t\t});\n\t}])\n\t.factory('Dog', ['Mammal', function (Mammal) {\n\t\treturn Mammal.extend({\n\t\t\tsetAge: function (age) {\n\t\t\t\tthis._super('setAge', age + 10);\n\t\t\t},\n\t\t\tgetAge: function () {\n\t\t\t\treturn 'Dog is ' + this._super('getAge') + ' years old';\n\t\t\t}\n\t\t})\n\t}])\n\t.controller('Ctrl', ['$scope', 'Dog', function ($scope, Dog) {\n\t\t$scope.dog = new Dog({age: 5});\n\t\t$scope.dog.getAge(); // Dog is 5 years old\n\t\t$scope.dog.setAge(8);\n\t\t$scope.dog.getAge(); // Dog is 18 years old\n\t}]);\n```\n\n##### Custom constructor\n```js\nangular.module('App', ['BaseClass'])\n\t.factory('Mammal', ['BaseClass', function (BaseClass) {\n\t\treturn BaseClass.extend({\n\t\t\tconstructor: function (args) {\n\t\t\t\tthis.age = args.age + 1;\n\t\t\t},\n\t\t\tsetAge: function (age) {\n\t\t\t\tthis.age = age;\n\t\t\t},\n\t\t\tgetAge: function () {\n\t\t\t\treturn this.age;\n\t\t\t}\n\t\t});\n\t}])\n\t.factory('Dog', ['Mammal', function (Mammal) {\n\t\treturn Mammal.extend({\n\t\t\tconstructor: function () {\n\t\t\t\tthis._super('constructor', arguments);\n\t\t\t},\n\t\t\tsetAge: function (age) {\n\t\t\t\tthis._super('setAge', age + 10);\n\t\t\t},\n\t\t\tgetAge: function () {\n\t\t\t\treturn 'Dog is ' + this._super('getAge') + ' years old';\n\t\t\t},\n\t\t})\n\t}])\n\t.controller('Ctrl', ['$scope', 'Dog', function ($scope, Dog) {\n\t\t$scope.dog = new Dog({age: 5});\n\t\t$scope.dog.getAge(); // Dog is 6 years old\n\t\t$scope.dog.setAge(8);\n\t\t$scope.dog.getAge(); // Dog is 18 years old\n\t}]);\n```\n\n##### With mixins\n```js\nangular.module('App', ['BaseClass'])\n\t.factory('mammalMixin', [function () {\n\t\treturn {\n\t\t\tgrow: function (number) {\n\t\t\t\tthis.age += number;\n\t\t\t},\n\t\t\tgetName: function () {\n\t\t\t\treturn this.name;\n\t\t\t}\n\t\t};\n\t}]);\n\t.factory('Mammal', ['BaseClass', 'mammalMixin', function (BaseClass, mammalMixin) {\n\t\treturn BaseClass.extend({\n\t\t\tconstructor: function (args) {\n\t\t\t\tthis.name = args.name;\n\t\t\t\tthis.age = args.age;\n\t\t\t},\n\t\t\tsetAge: function (age) {\n\t\t\t\tthis.age = age;\n\t\t\t},\n\t\t\tgetAge: function () {\n\t\t\t\treturn this.age;\n\t\t\t},\n\t\t\tmixins: [mammalMixin]\n\t\t});\n\t}])\n\t.factory('Cat', ['Mammal', function (Mammal) {\n\t\treturn Mammal.extend({\n\t\t\tgetAgeAndName: function () {\n\t\t\t\treturn 'Age: ' + this.getAge() + ' Name: ' + this.getName();\n\t\t\t}\n\t\t});\n\t}])\n\t.controller('Ctrl', ['$scope', 'Cat', function ($scope, Cat) {\n\t\t$scope.dog = new Cat({name: 'Meow', age: 5});\n\t\t$scope.dog.getAge(); // 5\n\t\t$scope.dog.setAge(8);\n\t\t$scope.dog.getAge(); // 8\n\t\t$scope.dog.getName(); // Meow\n\t\t$scope.dog.getAgeAndName(); // Age: 8 Name: Meow\n\t\t$scope.dog.grow(2);\n\t\t$scope.dog.getAge(); // 10\n\n\t}]);\n```\n\n## Running tests\n- Get the source code and in project root directory:\n\t- ```npm install```\n\t- ```npm run test```\n\n## Credits\n- Some ideas were borrowed from the following:\n\t- Axel Rauschmayer - http://www.2ality.com/\n\t- http://backbonejs.org/\n\n## License\nLicensed under the MIT license. Copyright (c) 2015 - 2017 Audrius Jakumavicius\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faj-dev%2Fangular-base-class","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faj-dev%2Fangular-base-class","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faj-dev%2Fangular-base-class/lists"}