JavaScript による
楽しいオブジェクト指向
プログラミング
片山 真也
どう書くの?
var Drug = function(name) {
this.name = name;

};
var hoge = new Drug(“hoge”);

var foo = new Drug(“foo”);
Drug.prototype.take = function() {
// 処理
}
hoge.take();
take

Drug

prototype

constructor

hoge

foo
name

name
“hoge”

“foo”
継承
var Super = function() {};
var Child = function() {};

Child.prototype = new Super();
Super

prototype

constructor

Child
constructor

prototype

プロトタイプ
チェーン
スーパーメソッド
Super.prototype.hoge = function(arg) {};

this
this.constructor
.prototype
.hoge .call(this, arg);
プライベート変数・関数
var Drug = function() { /* 初期化*/ };
(function() {
var private = function() {};
Drug.prototype.public = functio...
Upcoming SlideShare
Loading in...5
×

JavaScript による楽しいオブジェクト指向プログラミング

211

Published on

Published in: Technology, Health & Medicine
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
211
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
1
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

JavaScript による楽しいオブジェクト指向プログラミング

  1. 1. JavaScript による 楽しいオブジェクト指向 プログラミング 片山 真也
  2. 2. どう書くの?
  3. 3. var Drug = function(name) { this.name = name; }; var hoge = new Drug(“hoge”); var foo = new Drug(“foo”);
  4. 4. Drug.prototype.take = function() { // 処理 } hoge.take();
  5. 5. take Drug prototype constructor hoge foo name name “hoge” “foo”
  6. 6. 継承 var Super = function() {}; var Child = function() {}; Child.prototype = new Super();
  7. 7. Super prototype constructor Child constructor prototype プロトタイプ チェーン
  8. 8. スーパーメソッド Super.prototype.hoge = function(arg) {}; this this.constructor .prototype .hoge .call(this, arg);
  9. 9. プライベート変数・関数 var Drug = function() { /* 初期化*/ }; (function() { var private = function() {}; Drug.prototype.public = function() {}; })();
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×