Possible Duplicate:
Why does javascript object show different values in console in Chrome, Firefox, Safari?
I'm quite new to be using javascript's OOP concepts. I'm trying to understand the binding of javascript properties. Does javascript execute the below code, sequentially?
// main.js
function NameClass(){
this.name = "John"
this.age = 25
}
NameClass.prototype.change_my_name = function(new_name){
this.name = new_name
}
NameClass.prototype.change_my_age = function(new_age){
this.age = new_age
}
// main.html
<html>
<head>
<title>Javascript tutorial</title>
<script src="main.js"></script>
<script>
var nc = new NameClass()
console.log("nc before modification")
console.log(nc) // Prints Doe
nc.change_my_name("Doe")
console.log("nc after modification")
console.log(nc) // Prints Doe
</script>
</head>
<body></body>
</html>
Now, what is trick here?
- Why do I see "Doe" display both the times?
- What is the mechanism that I've to use here in order to display "John" the first time and "Doe" in the second?