<script> //原型对象有什么用 let date = new Date(); console.log(date) //Date Tue Dec 13 2022 19:19:05 GMT+0800 (中国标准时间) //目标:输出2022年12月13日 //建议:通过原型来扩展输出的格式======>扩展对象 Date.prototype.formate = function (){ let year = this.getFullYear(); let month = this.getMonth()+1; let date = this.getDate(); return `${year}年${month}月${date}日` } console.log(date.formate()); </script>
23_原型对象有什么用
最新推荐文章于 2024-07-30 10:56:44 发布