JSFiddle - React, Tailwind, and code Playground
by Rodolfo Hernandez
HTML
<div ng-app="app" ng-controller="main">
base: {{base}}
<br>
child: {{child}}
</div>
JavaScript
var app = angular.module('app', []);
app.factory('BaseService', function () {
//var service = {};
function service(){
this.message = "hello";
};
service.prototype.perform = function () {
console.log('perfom', this.message);
};
return new service();
});
app.factory('childBaseService',['BaseService', function(BaseService){
var childBaseService = function(){
BaseService.constructor.call(this)
this.message = 'world!';
};
childBaseService.prototype = Object.create(BaseService.constructor.prototype);
return new childBaseService();
}]);
app.controller('main',function($scope,BaseService, childBaseService){
$scope.base = BaseService.message;
console.log('controller fired!');
$scope.child = childBaseService.message;
console.log(BaseService instanceof BaseService.constructor); //true
console.log(childBaseService instanceof BaseService.constructor); //true
});