Created
June 6, 2012 11:05
-
-
Save chhantyal/2881294 to your computer and use it in GitHub Desktop.
JS OOP
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
function Subject(name, topics){ | |
this.name = name; | |
this.topics = topics; | |
} | |
var subjectMath = new Subject("Maths", ["sets", "trigonomitry", "algebra"]); | |
var subjectScience = new Subject("Science", ["Biology", "Astronomy", "Physics"]); | |
function Person(gender, age, currentSubject, currentTopicIndex){ | |
this.gender = gender; | |
this.age = age; | |
this.currentSubject = currentSubject; | |
this.currentTopicIndex = currentTopicIndex; | |
this.currentTopicName = this.currentSubject.topics[currentTopicIndex]; | |
} | |
Person.prototype.describe = function () { | |
console.log("person is " + this.gender + | |
", age " + this.age + " and reading " + | |
this.currentSubject.name + ' with topic ' + | |
this.currentTopicName); | |
} | |
var person1 = new Person("Male", 21, subjectMath,1); | |
var person2 = new Person("Female", 25,subjectMath,0); | |
person1.describe(); | |
person2.describe(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment