티스토리 뷰

//비전공자가 혼자 공부하는 공간입니다 

//잘못된 정보가 있을 수 있어요

 

see more ingredients를 누르면 좀 더 많은 재료를 볼 수 있는 detail.html 페이지가 열리게 만들었는데

이 둘은 구조는 거의 같은 데다가 같은 function을 쓰는 부분도 있지만 

완전히 다른 function을 쓰는 부분도 있다 

 

그래서 그런가 

home.html에서 오류가 나는 것을 고치면 detail.html에서 오류가 나고

detail.html에서 오류가 나는 것을 고치면 home.html에서 오류가 난다 

 

 

어찌저찌 검색해서 아래의 결론이 나왔다

아래의 함수들은 detail.html 페이지에서만 실행되도록 하는 코드 

✅ location.pathname

mdn을 보면 location.pathname 을 Web APIs 로 분류하고 있는데 그러면 내가 작성한 코드가 Web API인 건지 의문이 들었고

챗지피티에게 물어보았다 

 

Your code is not a Web API, but it is using Web APIs provided by the browser to achieve its functionality.
Web APIs are sets of methods and properties that browsers expose to allow developers to interact with the web platform. In your code snippet, the location.pathname property is a part of the Location interface, which is a Web API provided by the browser. By using location.pathname, your code is utilizing this Web API to get the path component of the URL.
So, your code is not a Web API itself, but it is using the Web APIs provided by the browser to retrieve information and interact with the web platform.

 

✅ Web API란

That's correct. Web APIs are not code that you write yourself, but rather pre-built interfaces provided by the browser that you can use in your own code.
웹 API는 사용자가 직접 작성하는 코드가 아니라 브라우저에서 제공하는 사전 구축된 인터페이스로 사용자 자신의 코드에서 사용할 수 있습니다. (이거 하나만 기억하면 될 것 같다)

When you use Web APIs, you are essentially calling pre-existing functionality that has been built into the browser. This can include things like window.alert(), XMLHttpRequest, and localStorage, among many others.
To use these Web APIs, you typically just need to call them in your JavaScript code, as you would with any other function or method. The browser then handles the underlying functionality for you, allowing you to use these APIs to interact with the web platform in various ways.

 

API를 막연히 데이터를 주고 받기 위한 방법, 통신 방법 혹은 대화 방법? 대화 규격 같은 추상적인 개념으로만 알고 있었는데 

체감상 조금 더 이해가 되는 것 같다 

 

깨끗한 콘솔창을 보니까 기분이 좋구만

하지만 아직 고칠 게 많이 남았다..... 내 struggling은 to be continued....

 

 

//비전공자가 혼자 공부하는 공간입니다 

//잘못된 정보가 있을 수 있어요