(in JavaScript)
Front-end Developer-> Engineer
JavaScript -> Programming Language
iPhone -> SmartPhone
(Information Hiding)
Phone.exploration = true ;
Father is handsome -> Child is handsome too.
Dogs woof, Cats meow, and Ducks quack
Javascript is a prototype-based language.
(which means no class !!)
從物件本身往prototype去尋找,當到最後都找不到時則會回傳null。
function Person(gender) {
this.gender = gender;
}
var person1 = new Person('Male');
Person.prototype.log = function(){
console.log(this.gender);
};
var bar = {b:20};
var foo = {a:10};
bar._proto_ = foo;
b | 20 |
_proto_ |
a | 10 |
_proto_ |
constructor | Object |
_proto_ | null |
bar
foo
Object_prototype
constructor | Object |
_proto_ | null |
Function
Object_prototype
prototype | |
_proto_ |
Function_prototype
constructor | |
_proto_ |
function Person(gender) {
this.gender = gender;
}
var person1 = new Person('Male');
function Person(gender) {
this.gender = gender;
}
var person1 = {};
Person.call(person1, 'Male');
function test(){
console.log(this);
}
test();
//Window...
var obj = {};
obj.test = function test(){
console.log(this);
};
obj.test();
//Object...
var obj = {};
obj.test = function test(){
function subFun(){
console.log(this);
}
subFun();
};
obj.test();
//Window...
function People(height,weight) {
this.body = true;
this.height = height || "";
this.weight = weight || "";
}
People.prototype.showBody = function(argument) {
console.log(this);
};
function Asia(color,language) {
this.color = color || "";
this.language = language || "";
}
Asia.prototype = new People;
Asia.prototype.showRacial = function(argument) {
console.log(this.color,this.language);
};
function Taiwan(height,weight,color,language) {
People.call(this,height,weight)
Asia.call(this,color,language)
}
Taiwan.prototype = new Asia;
var jeff = new Taiwan(180,70,"yellow","Mandarin");
console.log(jeff);
function Person() {
this.body = true;
this.height = height || "";
this.weight = weight || "";
}
Person.prototype.showBody = function() {
console.log(this);
};
function Asia() {
this.color = color || "";
this.language = language || "";
Person.call(this);
}
Asia.prototype = Object.create(Person.prototype);
function Taiwan(height,weight,color,language) {
People.call(this,height,weight)
Asia.call(this,color,language)
}
var rect = new Asia();
var jeff = new Taiwan(180,70,"yellow","Mandarin");
console.log(jeff);
https://datayo.wordpress.com/2015/10/04/
http://antrash.pixnet.net/blog/post/65311153
http://fstoke.me/blog/?page_id=1610
https://pjchender.blogspot.tw/2016/03/javascriptthisbug.html
https://developer.mozilla.org/zh-TW/docs/Web/JavaScript/Guide/Details_of_the_Object_Model
https://github.com/rus0000/jsinheritance
http://blog.dylango.com/2013/10/24/javascript-patterns-reading-notes-6-code-reuse-patterns/