# 元编程

## 元编程详解

元编程时指操作目标时是程序本身的行为特性的编程----是对程序的编程的编程。

用for in 循环枚举对象的键，或者检查一个对象是否是某个 “类构造器”的实例，也都是常见的例子 元编程有以下要点

* 代码查看自身
* 代码修改自身
* 代码修改默认语言特性
* 影响其他代码

直接上例子

```js
function foo(cb){
    //这里cb()的名称是什么
}

foo( function(){
    //我是匿名的
})

```

上面涉及到函数的名称， name 属性，是的函数有一个名为 name 的属性，其在词法作用域下。绑定。

## 元属性

元属性以属性访问的形式提供特殊的其他方法无法获取的元信息。

以new\.target 为例， 关键字 new 用作属性访问上下文。 而在构造器调用 （通过 new 出发的函数/方法） 内部使用 new\.traget时， new 成了一个虚拟上下文，使得 new\.target 能够指向 调用 new 的目标构造器。

这也是元编程的例子， 从构造器调用内部确定最初 new 的目标时什么， 通用地说用于内省（检查类型/ 结构） 或者静态属性访问。

```js



```


---

# 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://shenjunhong.gitbook.io/blog/js/es6-zhi-yuan-bian-cheng-ni-hao.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.
