Father.js
/**
* Father - 父對象
*/
function Father(name)
{
/**
* 私有屬性:
*/
var wife = "嫦娥";
/**
* 公開屬性
*/
this.name = "康熙";
/**
* 模擬一個構造函數
*/
this._constructor = function()
{
if(name) this.name = name;
console.log("Father的構造函數,父親的名字是:"+name);
}
/**
* 私有方法
*/
var setMoney = function(num)
{
return num;
}
/**
* 公開方法
*/
this.eat = function(name)
{
return "喜歡吃:"+name;
}
this._constructor();
}
/**
* 靜態屬性
*/
Father.car = "奧迪";
/**
* 靜態方法
*/
Father.driveCar = function()
{
return Father.car;
}
Son.js
/**
* Son - 子對象
*/
function Son()
{
/**
* 實現繼承
*/
Father.call(this,'成龍');
}
new Son().eat('面包')