Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Safari만 spread operator 작동이 다른가 #72

Open
SeonHyungJo opened this issue Aug 12, 2020 · 0 comments
Open

Safari만 spread operator 작동이 다른가 #72

SeonHyungJo opened this issue Aug 12, 2020 · 0 comments
Labels
💌 JavaScript 공부를 해도해도 어려운 JavaScript

Comments

@SeonHyungJo
Copy link
Owner

SeonHyungJo commented Aug 12, 2020

let extraServiceAvailable = {
  "waterLarge": false,
  "waterSmall": false,
  "cleaning": false,
  "additionalReturnPlace": false,
  "baggage": false
}

위와 같은 부가서비스를 제공여부에 대한 데이터 기본값이 들어있다. 그리고 API로 현재 제공되는 부가서비스를 가져오는 경우

{
  "waterLarge": false,
  "waterSmall": true,
  "cleaning": true,
  "additionalReturnPlace": false,
  "baggage": false
}

위와 같이 true로 변경되서 들어온다. 이제 기본값과 API로 넘어온 값을 합치려고 한다.

let extraServiceAvailable = {
  "waterLarge": false,
  "waterSmall": false,
  "cleaning": false,
  "additionalReturnPlace": false,
  "baggage": false
}

let APIExtra = {
  "waterLarge": false,
  "waterSmall": true,
  "cleaning": true,
  "additionalReturnPlace": false,
  "baggage": false
}

let result = {...extraServiceAvailable, ...APIExtra}

기본값에 작성한 순서를 유지하면서 API값을 합치기 위해서 Spread Operator를 사용했다.
그런데 사파리에서는 순서가 바뀌게 된다.

// 크롬
{waterLarge: false, waterSmall: true, cleaning: true, additionalReturnPlace: false, baggage: false}

// 사파리
{waterLarge: false, additionalReturnPlace: false, baggage: false, waterSmall: true, cleaning: true}

위와 같은 상황을 방지하기 위해서 forEach()를 사용해서 구현하였다.

@SeonHyungJo SeonHyungJo added the 💌 JavaScript 공부를 해도해도 어려운 JavaScript label Aug 12, 2020
@SeonHyungJo SeonHyungJo changed the title 왜 safari만 spread syntax 작동이 다른가 WIP 왜 safari만 spread syntax 작동이 다른가 Aug 18, 2020
@SeonHyungJo SeonHyungJo changed the title WIP 왜 safari만 spread syntax 작동이 다른가 Safari만 spread syntax 작동이 다른가 Sep 3, 2020
@SeonHyungJo SeonHyungJo changed the title Safari만 spread syntax 작동이 다른가 Safari만 spread operator 작동이 다른가 Sep 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💌 JavaScript 공부를 해도해도 어려운 JavaScript
Projects
None yet
Development

No branches or pull requests

1 participant