function A() {
this.a = 'this is a';
var b = 'this is b';
}
function B() {
var self = this;
this.c = 'this is c';
var d = 'this is d';
// a: undefined, b: undefined, c: this is c, d: this is d
$("#txt1").text('a: ' + A.a + ', b: ' + b + ', c: ' + this.c + ', d: ' + d);
C();
function C() {
// this.c is not defined here
// a: undefined, b: undefined, c: this is c, d: this is d
$("#txt2").text('a: ' + A.a + ', b: ' + b + ', c: ' + self.c + ', d: ' + d);
}
}
B.prototype = new A();
var b = new B();
B類和內部功能C可能變得可變a
和b
?是否有可能在JavaScript中的父類中獲取元素?
小提琴文件是在這裏:http://jsfiddle.net/vTUqc/5/
沒有
現在
b
是的A
實例訪問...'了'和'B'是本地到那些功能。 –@FelixKling這只是一半。 'A'的任何實例都可以訪問'a',而'B'的原型恰好是'A'的實例。 –
@Asad:啊,我掃描的代碼太快了,我的意思是'b'。 –