Created
April 27, 2013 10:21
-
-
Save ide-an/5472614 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
// Foo.prototype.f = ...でメソッドを追加するスタイル | |
var Foo = function(){}; | |
Foo.prototype.f = function(){ | |
console.log("foo"); | |
}; | |
Foo.prototype.g = function(){ | |
console.log("bar"); | |
}; | |
// Bar.prototype = { ... } でメソッドを追加するスタイルだと... | |
var Bar = function(){}; | |
//あらかじめ追加したフィールド(メソッド)fが... | |
Bar.prototype.f = function(){ | |
console.log("foo"); | |
}; | |
//うっかり消されてしまう可能性がある | |
Bar.prototype = { | |
g: function(){ | |
console.log("bar"); | |
} | |
}; | |
var bar = new Bar(); | |
bar.g();//OK | |
bar.f();//error!! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment