Created
July 11, 2013 21:04
-
-
Save aligneddev/5979233 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en-us"> | |
<head> | |
<meta charset="utf-8"> | |
<title>JS inheritance</title> | |
</head> | |
<body> | |
<div id="mainContent"> | |
</div> | |
<script src="https://ajax.aspnetcdn.com/ajax/knockout/knockout-2.2.1.js"></script> | |
<script> | |
document.onload = function(){ | |
var labelVm = new DataLabelVm(100); | |
labelVm.Init(); | |
var indicatorVm = new IndicatorVm(); | |
indicatorVm.Init(); | |
}; | |
</script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*global ko, $, window, toastr */ | |
var mstar = mstar || {}; | |
mstar.commonDashboard = mstar.commonDashboard || {}; | |
mstar.components = mstar.components || {}; | |
LayoutElementsBase = function () { | |
'use strict'; | |
var tempData, | |
isDesignMode = false, | |
containerWidth, | |
containerHeight, // TODO: remove? | |
top, | |
left, | |
width, | |
height, | |
zIndex, | |
// needs to be set by the inheriter | |
id, | |
domIdPrefix, | |
domId, | |
pageWidth, // TODO: remove? | |
pageHeight; // TODO: remove? | |
function construct() { | |
window.console.log('LEB constructor'); | |
} | |
construct.prototype.Init = function () { | |
window.console.log('LEB init'); | |
}; | |
construct.prototype.AfterInit = function () { | |
}; | |
construct.prototype.Resize = function () { | |
}; | |
construct.prototype.Top = 30; | |
return construct; | |
//return { | |
// IsDesignMode: isDesignMode, | |
// ContainerWidth: containerWidth, | |
// ContainerHeight: containerHeight, | |
// Top: top, | |
// Left: left, | |
// Width: width, | |
// Height: height, | |
// ZIndex: zIndex, | |
// Id: id, | |
// DomIdPrefix: domIdPrefix, | |
// DomId: domId, | |
// PageWidth: pageWidth, | |
// PageHeight: pageHeight, | |
// Init: init, | |
// AfterInit: afterInit, | |
// Resize: resize | |
//}; | |
}(); | |
ComponentBase = (function () { | |
// constructor | |
function construct() { | |
window.console.log("CB constructor"); | |
LayoutElementsBase.apply(this, arguments); | |
} | |
// make the prototype object inherit from the Parent's one | |
construct.prototype = Object.create(LayoutElementsBase.prototype); | |
construct.parent = LayoutElementsBase.prototype; | |
// public functions | |
construct.prototype.Init = function() { | |
window.console.log("init in CB"); | |
this.Top = 15; | |
window.console.log(this.Top); | |
window.console.log(construct.parent.Top); | |
construct.parent.Init(); | |
}; | |
return construct; | |
})(); | |
DataLabelVm = (function () { | |
// constructor | |
function construct(topParam) { | |
window.console.log("data label constructor"); | |
ComponentBase.apply(this, arguments); | |
this.Top = topParam; | |
} | |
// make the prototype object inherit from the Parent's one | |
construct.prototype = Object.create(ComponentBase.prototype); | |
construct.parent = ComponentBase.prototype; | |
// public functions | |
construct.prototype.Init = function() { | |
window.console.log("init in data label"); | |
window.console.log(this.Top); | |
construct.parent.Init(); | |
}; | |
return construct; | |
})(); | |
IndicatorVm = (function () { | |
// constructor | |
function construct() { | |
window.console.log("indicator constructor"); | |
ComponentBase.apply(this, arguments); | |
} | |
// make the prototype object inherit from the Parent's one | |
construct.prototype = Object.create(ComponentBase.prototype); | |
construct.parent = ComponentBase.prototype; | |
// public functions | |
construct.prototype.Init = function() { | |
window.console.log("init in indicator"); | |
this.Top = 15; | |
window.console.log(this.Top); | |
window.console.log(construct.parent.Top); | |
construct.parent.Init(); | |
}; | |
return construct; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment