Created
July 26, 2012 11:42
-
-
Save ychaouche/3181595 to your computer and use it in GitHub Desktop.
javascript / C++
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
Do you agree what that statement below ? | |
"In Javascript, it is preferable to declare methods outside of the function definition. | |
Because if you define it inside the function, it's like you're defining a method inside a constructor. | |
You usually don't do that do you ? usually a constructor just initialises attributes. | |
You would declare the methods outside of the function definition." | |
So instead of this : | |
var Dog = function(name,age,sex){ | |
this.name = name; | |
this.age = age; | |
this.sex = sex; | |
Dog.prototype.bark = function(){console.debug("arf !");}; | |
} | |
You write this | |
var Dog = function(name,age,sex){ | |
this.name = name; | |
this.age = age; | |
this.sex = sex; | |
} | |
Dog.prototype.bark = function(){console.debug("arf !");}; | |
Isn't this a little bit like in C++ ? where methods are defined outside of the the class definition ? | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment