Spring data jpa 时间注解

SegmentFault

共 1216字,需浏览 3分钟

 ·

2020-08-23 18:27

来源:SegmentFault 思否
作者:大牛哥




先定义一个构造函数:


function Person(name,age){    this.name = name;    this.age = age;    this.say = function(){        console.log("hello world")    }}Person.prototype.gender = male;


1.原型链继承:将子类的构造函数的原型变为父类的实例对象


Student.prototype = new Person();Student.prototype.constructor = Student


优点:实现简单
缺点:无法向父构造函数传参


2.通过构造函数继承


function Student(name,age){    Person.call(this,name,age)    this.name = name;    this.age = age;    this.say = function(){        console.log("hello world")    }}


缺点:无法访问父构造函数的原型中的方法


3.将子构造函数的原型修改为父构造函数的原型


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();


缺点:调用了两次父类构造函数,消耗内存





点击左下角阅读原文,到 SegmentFault 思否社区 和文章作者展开更多互动和交流。

- END -

浏览 9
点赞
评论
收藏
分享

手机扫一扫分享

举报
评论
图片
表情
推荐
点赞
评论
收藏
分享

手机扫一扫分享

举报