function student(props)
student.prototype.hello=function()
function createstudent(props))
}var xiaoming=createstudent();
xiaoming.hello();
//hello xiaoming
傳進乙個陣列
function animal(name,age,grade)
animal.prototype.hello=function()
var chicken=new animal('
chicken
',3,12
); chicken.hello();
//hello chicken
我理解的建構函式就是用new()例項化去構造
看了原型繼承,發現原型繼承不了
所以就看**
function student(name)
student.prototype.hello=function()
function cat(grade)
var a=new cat()//
a.name=unname,a.grade=12,a.hello() is not a function不可以繼承student的原型,
function f(){}
f.prototype=student.prototype;
cat.prototype=new
f()
var b=new cat();//
b.name=unname,b.grade=12,b.hello()='hello unname'可以繼承student的原型
通過call來呼叫繼承,並繫結this
也可以用class來extends
class
student
hello()
}class
cat extends student
mygrade()
}var a=new
cat()
都能用
更多專業前端知識,請上
【猿2048】www.mk2048.com
建構函式模式
已經n天沒有學習了。中間辦了好多事,關乎人生大事,所以斷了學習。貌似理由很充分。總之,今天是十一長假的第二天,沒打算出去玩,把前段時間沒學習的趕緊彌補一下吧。上回說到建立物件時用的工廠模式,減少了 重複,可是不能區分出每個例項所對應的物件,於是建構函式登場了。function createobjec...
工廠模式與建構函式模式
簡單工廠模式 以object建構函式或字面量的方式建立物件有著重複性,會產生大量重複 的缺陷,由此,便出現了工廠模式。function createobj name,age var obj1 createobj 小明 66 var obj2 createobj 小白 13 console.log o...
詳解建構函式模式
前言 雖然ecmascript從技術上講是一門物件導向的語言,但是它不具備傳統的物件導向語言所支援的類和介面等基本結構。但在es5中,有與類相似的引用型別。引用型別描述一類物件所具有的屬性和方法,引用型別的值 物件 是引用型別的乙個例項,所以也被稱為物件定義。新物件是使用new 操作符後跟乙個建構函...