Created
August 8, 2014 05:09
-
-
Save jaywon/259f78c1b5988aa6ffe7 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
// Set up base class DIV | |
function Div(name){ | |
this.name = name; | |
this.element = null; | |
} | |
Div.prototype.draw = function(){ | |
// $("p").append("<div>Div</div>"); | |
console.log('draw works'); | |
this.element = $("<div>Div</div>"); | |
// console.log(this.element); | |
$("p").append(this.element); | |
$(this.element).click(this.click); | |
} | |
// Set up DIV subclass BLUE | |
function BlueDiv(color){ // function creates class definition | |
this.color = '#0000FF' | |
} | |
BlueDiv.prototype = new Div(); | |
// Set up DIV subclass RED | |
function RedDiv(color){ // function creates class definition | |
this.color = '#FF0000' | |
} | |
RedDiv.prototype = new Div(); | |
// Click handler | |
BlueDiv.prototype.click = function(){ | |
console.log(this.color); | |
$(this.element).css("color", this.color); | |
console.log('blue click'); | |
}; | |
RedDiv.prototype.click = function(){ | |
console.log(this.color); | |
$(this.element).css("color", this.color); | |
console.log('red click'); | |
}; | |
// ---------------------------------------------------- | |
// Draw classes | |
$(document).ready(function(){ | |
var color = new BlueDiv(); | |
color.draw(); | |
var color = new RedDiv(); | |
color.draw(); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment