*Every Object has an internal link to another object called prototype
Creating an object:
Javascript Core Object ref:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Predefined_Core_Objects
Javascript Core Object ref:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Predefined_Core_Objects
syntax
constructs:
var
o = {a: 1};
//o ---> Object.prototype ---> null
var
a = ["yo", "whadup", "?"];
//a ---> Array.prototype ---> Object.prototype ---> null
function f(){
return 2;
}
//f ---> Function.prototype --->
Object.prototype ---> null
Constructor:
function Graph() {
this.vertexes = [];
this.edges = [];
}
Graph.prototype = {
addVertex: function(v){
this.vertexes.push(v);
}
};
var g = new Graph();
//Graph ---> Graph.prototype --->
Object.prototype
var a = {a: 1};
var b = Object.create(a);
// b ---> a ---> Object.prototype
---> null
var c = Object.create(b);
// c ---> b ---> a --->
Object.prototype ---> null
var d = Object.create(null);
// d ---> null
沒有留言:
張貼留言