Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // "class" Square (capitalize by convention)
- function Square(side_length) {
- this.side = side_length; // "instance variable"
- this.area = function() { // "instance method"
- return this.side*this.side;
- }
- }
- // "instance"
- var someSquare = new Square(3);
- // better, since keeps instance methods separate and avoids having N copies of them
- function Square(side_length) {
- this.side = side_length;
- }
- // .prototype is a special property defined only on functions. The 'new'
- // constructor sets __proto__ property of new object from .prototype's value.
- // Also, __proto__ is not writable in IE's implementation of JScript.
- Square.prototype.area = function() {
- return this.side * this.side;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement