# [JavaScript] 物件傳參考特性 ###### tags: `JavaScript` ### 解說傳值、傳參考  ### 應對方式:Object.assign  ### 操作實例 ``` openModal(item){ //this.tempProduct= item; //因為物件傳參考的特性,直接用item會與tmepProduct相同 this.tempProduct= Object.assign({},item); //可採用es6語法,將item傳自獨立的空物件裡,才不會互相渲染 }, ``` * 無法直接指定匯入變數中,因傳參考的特性會互相渲染,需將item傳入空物件裡,才能順利使用。 ``` openModal(isNew, item) { if (isNew) { this.tempProduct = {}; this.isNew = true; } else { this.tempProduct = { ...item }; // 採用es6語法,將item傳自獨立的空物件裡,避免互相渲染 this.isNew = false; } $('#productModal').modal('show'); }, ``` * 也能使用ES6語法...來避免傳參考特性
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up