美團筆試題(JavaScript)

(前端)請使用JS實現一個meituan對象,其中包含兩個可執行的函數getVersion()和setVersion(),滿足條件如下:

meituan.getVersion();//輸出默認0.0.1

meituan.setVersion(‘0.0.2’);//

meituan.getVersion();//輸出 0.0.2


代碼如下:

<script type="text/javascript">
var meituan=function(){
this.version='0.0.1';
this.setVersion=function(version){
this.version=version;
}
this.getVersion=function(){
alert(this.version);
}
}
var myVersion=new meituan();
myVersion.setVersion('0.0.2');
myVersion.getVersion();
</script>

發佈了34 篇原創文章 · 獲贊 12 · 訪問量 7萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章