Re: [問題] javascript 的 private 屬性
Private members are made by the constructor. Ordinary vars and parameters of
the constructor becomes the private members.
function Container(param) {
this.member = param;
var secret = 3;
var that = this;
}
This constructor makes three private instance variables: param, secret, and
that. They are attached to the object, but they are not accessible to the
outside, nor are they accessible to the object's own public methods.
by http://javascript.crockford.com/private.html
---
我知道private的用意就是保護變數不被亂動
但另一個他該有的功能是: 在自己的method中能被使用
不然我為了自己要用他就得開getter給他,如此變成您說的無意義了
我想js的邏輯跟C應該不太一樣,所以有點困惑中
但應該有個對應的做法
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 220.133.61.45
推
02/22 17:44, , 1F
02/22 17:44, 1F
→
02/22 17:45, , 2F
02/22 17:45, 2F
→
02/22 17:46, , 3F
02/22 17:46, 3F
→
02/22 17:47, , 4F
02/22 17:47, 4F
→
02/22 17:54, , 5F
02/22 17:54, 5F
→
02/22 17:55, , 6F
02/22 17:55, 6F
→
02/22 18:09, , 7F
02/22 18:09, 7F
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 2 之 5 篇):