# Snippets

## customBind

```javascript
Function.prototype.customBind = function (obj, ...args) {
  if (obj == null) {
    obj = this
  }
  return (...closureFnArgs) => {
    this.apply(obj, args.concat(closureFnArgs))
  }
}
```

## 숫자 천단위마다 콤마 찍기

```javascript
const num = 10203040
const num2 = 10203040.12345

console.log(num.toLocaleString()) // 10,203,040
console.log(num2.toLocaleString()) // 기본으로 소수점 3자리에서 끊김 10,203,040.123
console.log(num2.toLocaleString(undefined, { maximumFractionDigits: 5 })) // 10,203,040.12345
```

## 조건에 따른 프로퍼티 삽입문 축약

```javascript
const keyword = document.querySelector('.input').value
const user = { name: 'lee', gender: 'male' }

const query = {
  collection: 'Cats',
  sort: 'asc',

  ...(keyword && { keyword }), // keyword가 있으면 keyword: keyword 없으면 무시
  ...(user.gender === 'male' && user), // user.gender가 male이면 user객체의 프로퍼티를 삽입 없으면 무시
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://lsw0150305.gitbook.io/til/javascript/snippets.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
