Spring data jpa 時間注解
先定義一個構造函數(shù):
function Person(name,age){this.name = name;this.age = age;this.say = function(){console.log("hello world")}}Person.prototype.gender = male;
1.原型鏈繼承:將子類的構造函數(shù)的原型變?yōu)楦割惖膶嵗龑ο?/span>
Student.prototype = new Person();Student.prototype.constructor = Student
優(yōu)點:實現(xiàn)簡單
缺點:無法向父構造函數(shù)傳參
2.通過構造函數(shù)繼承
function Student(name,age){Person.call(this,name,age)this.name = name;this.age = age;this.say = function(){console.log("hello world")}}
缺點:無法訪問父構造函數(shù)的原型中的方法
3.將子構造函數(shù)的原型修改為父構造函數(shù)的原型
function Student(name,age){Person.call(this,name,age)this.name = name;this.age = age;this.say = function(){console.log("hello world")}}Student.prototype = Person.prototypeStudent.prototype.constructor = Student
缺點:破壞了原型鏈,給子類的原型添加屬性父類原型也會添加
4.將子類的原型設置為父類的實例對象
function Student(name,age){Person.call(this,name,age)this.name = name;this.age = age;this.say = function(){console.log("hello world")}}Student.prototype = new Person();
缺點:調(diào)用了兩次父類構造函數(shù),消耗內(nèi)存

評論
圖片
表情
