函数参数传递方式(原始值和引用值)

以下引用阮一峰网道 https://wangdoc.com/javascript/types/function.html#%E7%AC%AC%E4%B8%80%E7%AD%89%E5%85%AC%E6%B0%91

 

 看下边的例子:

 function text(person) {
        person.age = 40
        person = {
          name: 'yyyyy',
          age: 30
        }
        return person
      }
      const p1 = {
        name: 'aaaaa',
        age: 25
      }
      const p2 = text(p1)
      console.log(p1);
      console.log(p2);

打印结果:

{name: "aaaaa", age: 40}
{name: "yyyyy", age: 30}

 

posted @ 2020-04-10 10:10  性感的沙皮  阅读(231)  评论(0编辑  收藏  举报