wangqilangfff 2022-04-22 13:04 采纳率: 80%
浏览 146
已结题

原型对象创建方法案例 javascript 具体实现步骤如这个yuan代码有吗?

#原型对象创建方法案例
javascript
具体实现步骤如下:

a) 创建一个构造函数Clothes()。

b) 基于Clothes()新增2个对象clothes1、clothes2。

c) 使用prototype给构造函数添加type属性。

d) 使用prototype属性,给构造函数Clothes()添加Clothes_fun方法。

e) 在页面中输出结果。
yuan代码有吗?

  • 写回答

1条回答 默认 最新

  • Heerey525 前端领域新星创作者 2022-04-22 13:45
    关注

    我按照步骤写了下

    
    // a) 创建一个构造函数Clothes()
          function Clothes() {}
    
          // b) 基于Clothes()新增2个对象clothes1、clothes2
          let clothes1 = new Clothes()
          let clothes2 = new Clothes()
    
          // c) 使用prototype给构造函数添加type属性
          Clothes.prototype.type = 'type'
    
          // d) 使用prototype属性,给构造函数Clothes()添加Clothes_fun方法
          Clothes.prototype.Clothes_fun = function() {
            console.log('Clothes_fun')
          }
    
          // e) 在页面中输出结果
          document.write(clothes1 + '<br>')
          document.write(JSON.stringify(clothes2))
    
          console.log('clothes1', clothes1)
          console.log('clothes2', clothes2)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 4月22日
  • 已采纳回答 4月22日
  • 创建了问题 4月22日

悬赏问题

  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程