/**
* @Author: 魏青峰
* @Date: 2019-01-16 17:37:49
* @param {type}
* @return:
* @Description: ES5:類定義方式
*/
function Point(config){
this._config = config;
//操作當前對象的屬性,屬性可以覆蓋原型
this.toString2 =function(){console.log('2') };
Point.prototype.toString2 =function(){console.log('3')};
}
//給原型添加方法
Point.prototype = {
toString1() {
console.log('1')
},
toValue1() {}
}
export {Point}
// ES6:類定義方式
/**
* @Author: 魏青峰
* @Date: 2019-01-16 17:37:28
* @param {type}
* @return:
* @Description: ES6:類定義方式
*/
class Line{
constructor(config){
this._config = config;
//操作當前對象的屬性,屬性可以覆蓋原型
this.toString=function(){ console.log('obj') }
}
toString(){
console.log('prt')
}
toValue(){}
}
export {Line}
更多建議: