Explanation of passing by value of js function parameters

一个新手
Release: 2017-09-26 09:36:55
Original
1526 people have browsed it


function setName(obj){ obj.name='test'; obj=new Object() obj.name='test1'; }var person=new Object(); setName(person); console.log(person.name);//输出test
Copy after login

The parameters of the above function are passed by value. If obj is passed by reference, person is also modified.
When the reference type is passed to the parameter of the function, the value saved by person is copied to the parameter of the function, and the value points to the application of the object. Obj=new Object() in the function is equivalent to modifying the internal obj. At this time, obj no longer points to the object pointed to by person.

The above is the detailed content of Explanation of passing by value of js function parameters. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!