Angular: Empty Fiddle
http://angularjs.org/
HTML
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-controller="FirstCtrl as first">
{{ first.sayHi() }}
</div>
<div ng-controller="SecondCtrl as second">
{{ second.sayHi() }}
</div>
JavaScript
var myApp = angular.module('myApp',[]);
function BaseCtrl() {
}
BaseCtrl.prototype.sayHi = function() {
return "Hello, " + this.name + "!";
}
FirstCtrl.prototype = Object.create(BaseCtrl.prototype);
SecondCtrl.prototype = Object.create(BaseCtrl.prototype);
function FirstCtrl() {
this.name = "Foo";
}
function SecondCtrl() {
this.name = "Bar";
}