InternVL2 Docker 镜像使⽤说明

InternVL2 Docker 镜像使⽤说明

俗世奇人 by  InternVL2 Docker 镜像使⽤说明    概述    本⽂旨在为⽤⼾提供⼀个⽅便的⽅式来配置所需的 Python 环境,以便运⾏InternVL2。通过使⽤    Docker,⽤⼾可以在隔离的容器中轻松设置和管理依赖项,⽆需担⼼与系统环境的冲突或其他依赖问    题。本⽂以运⾏InternVL2-1B为⽰例给出详细步骤,如有遇到报错请先参考:    https://docs.docker.com/manuals/    https://yeasy.gitbook.io/docker_practice    https://chatgpt.com/    ⽅法1:在线拉取    前提条件    1.  安装了 Docker 的系统    2.  可以通过某种⽅式顺畅连接到 https://hub.docker.com/    3.  cuda>=11.8    步骤 1 :拉取Docker镜像    1.  使⽤  docker pull  命令拉取镜像。命令格式为:    1  docker pull qishisurenhhh/internvl:latest    如果你没有指定  <tag>  ,默认会拉取  latest  标签的镜像。    1  latest: Pulling from qishisurenhhh/internvl    2  Digest: sha256: 68 db47419cb037d27e3afd6d978fb78d630e4bc0d2d33096350189a337ad9fa5    3  Status: Image is up to date for qishisurenhhh/internvl:latest    4  docker.io/qishisurenhhh/internvl:latest    步骤 2:运⾏ Docker 容器    1.  运⾏ Docker 容器:    使⽤以下命令运⾏加载的 Docker 镜像,并根据需要覆盖默认环境变量: 1  docker run --gpus all \    2  -e CUDA_DEVICE=0 \    3  -e MODEL_PATH= 'OpenGVLab/InternVL2-1B'  \    4  -e http_proxy= \    5  -e https_proxy= \    6  -e HTTP_PROXY= \    7  -e HTTPS_PROXY= \    8  -it qishisuren/internvl:v2    docker run    这是⽤于运⾏容器的 Docker 命令。    --gpus all    这部分⽤于告诉 Docker 运⾏的容器可以访问所有可⽤的 GPU。确保 Docker 守护进程配置了 NVIDIA    GPU ⽀持。    -e CUDA_DEVICE=0    这⾏⽤于设置容器内的环境变量  CUDA_DEVICE  ,值为  0  。这个变量可以被容器内的应⽤程序访    问,⽤于指定要使⽤的 CUDA 设备编号。    -e MODEL_PATH='path/to/other/model'    这⾏⽤于设置容器内的环境变量  MODEL_PATH  ,默认值为  'OpenGVLab/InternVL2-1B'  。    -e http_proxy= -e https_proxy= -e HTTP_PROXY= -e HTTPS_PROXY=    如果您的容器需要通过代理访问互联⽹,可以在此设置代理地址。    -it    这部分表⽰以交互模式运⾏容器,并且分配⼀个伪终端。它组合了  -i  (交互式)和  -t  (伪终端)    两个选项。    输出    1  ==========    2  == CUDA ==    3  ==========    4    5  CUDA Version  11.8.0    6    7  Container image Copyright (c)  2016-2023 , NVIDIA CORPORATION & AFFILIATES. All    rights reserved.    8 9  This container image and its contents are governed by the NVIDIA Deep Learning    Container License.    10  By pulling and using the container, you accept the terms and conditions of    this license:    11  https: //developer.nvidia.com/ngc/nvidia-deep-learning-container-license   12    13  A copy of this license is made available in this container at /NGC-DL   CONTAINER-LICENSE for your convenience.    14    15  Using CUDA device:  4    16  Using model path: OpenGVLab/InternVL2 -1 B    17  /usr/local/lib/python3 .10 /dist-packages/huggingface_hub/file_download.py: 1150 :    FutureWarning: `resume_download` is deprecated and will be removed in version    1.0.0 . Downloads always resume when possible. If you want to force a new    download, use `force_download=True`.    18  warnings.warn(    19  config.json:  100 %|    ████████████████████████████████████████████████████████████████    ████████████████████████████████████████████████████████████████    ██████████████████████████████████████████████████████████ |    3.68 k/ 3.68 k [ 00 : 00 < 00 : 00 ,  35.2 MB/s]    20  configuration_internvl_chat.py:  100 %|    ████████████████████████████████████████████████████████████████    ████████████████████████████████████████████████████████████████    ███████████████████████████████████████ |  3.80 k/ 3.80 k [ 00 : 00 < 00 : 00 ,    30.3 MB/s]    21  configuration_intern_vit.py:  100 %|    ████████████████████████████████████████████████████████████████    ████████████████████████████████████████████████████████████████    ██████████████████████████████████████████ |  5.55 k/ 5.55 k [ 00 : 00 < 00 : 00 ,    39.5 MB/s]    22  A new version of the following files was downloaded from    https: //huggingface.co/OpenGVLab/InternVL2-1B:   23  - configuration_intern_vit.py    24  . Make sure to double-check they do not contain any added malicious code. To    avoid downloading new versions of the code file, you can pin a revision.    25  A new version of the following files was downloaded from    https: //huggingface.co/OpenGVLab/InternVL2-1B:   26  - configuration_internvl_chat.py    27  - configuration_intern_vit.py    28  . Make sure to double-check they do not contain any added malicious code. To    avoid downloading new versions of the code file, you can pin a revision.    29  modeling_internvl_chat.py:  100 %|    ████████████████████████████████████████████████████████████████    ████████████████████████████████████████████████████████████████    ████████████████████████████████████████████ |  15.2 k/ 15.2 k    [ 00 : 00 < 00 : 00 ,  3.82 MB/s] 30  modeling_intern_vit.py:  100 %|    ████████████████████████████████████████████████████████████████    ████████████████████████████████████████████████████████████████    ████████████████████████████████████████████████ |  18.2 k/ 18.2 k    [ 00 : 00 < 00 : 00 ,  112 MB/s]    31  A new version of the following files was downloaded from    https: //huggingface.co/OpenGVLab/InternVL2-1B:   32  - modeling_intern_vit.py    33  . Make sure to double-check they do not contain any added malicious code. To    avoid downloading new versions of the code file, you can pin a revision.    34  conversation.py:  100 %|    ████████████████████████████████████████████████████████████████    ████████████████████████████████████████████████████████████████    ██████████████████████████████████████████████████████ |    15.0 k/ 15.0 k [ 00 : 00 < 00 : 00 ,  3.99 MB/s]    35  A new version of the following files was downloaded from    https: //huggingface.co/OpenGVLab/InternVL2-1B:   36  - conversation.py    37  . Make sure to double-check they do not contain any added malicious code. To    avoid downloading new versions of the code file, you can pin a revision.    38  A new version of the following files was downloaded from    https: //huggingface.co/OpenGVLab/InternVL2-1B:   39  - modeling_internvl_chat.py    40  - modeling_intern_vit.py    41  - conversation.py    42  . Make sure to double-check they do not contain any added malicious code. To    avoid downloading new versions of the code file, you can pin a revision.    43  /usr/local/lib/python3 .10 /dist-packages/huggingface_hub/file_download.py: 1150 :    FutureWarning: `resume_download` is deprecated and will be removed in version    1.0.0 . Downloads always resume when possible. If you want to force a new    download, use `force_download=True`.    44  warnings.warn(    45  model.safetensors:  100 %|    ████████████████████████████████████████████████████████████████    ████████████████████████████████████████████████████████████████    ████████████████████████████████████████████████████ |  1.88 G/ 1.88 G    [ 03 : 00 < 00 : 00 ,  10.4 MB/s]    46  generation_config.json:  100 %|    ████████████████████████████████████████████████████████████████    ████████████████████████████████████████████████████████████████    ██████████████████████████████████████████████████ |  69.0 / 69.0    [ 00 : 00 < 00 : 00 ,  722 kB/s]    47  tokenizer_config.json:  100 %|    ████████████████████████████████████████████████████████████████    ████████████████████████████████████████████████████████████████    ████████████████████████████████████████████████ |  3.02 k/ 3.02 k    [ 00 : 00 < 00 : 00 ,  34.3 MB/s] 48  vocab.json:  100 %|    ████████████████████████████████████████████████████████████████    ████████████████████████████████████████████████████████████████    ███████████████████████████████████████████████████████████ |    3.38 M/ 3.38 M [ 00 : 00 < 00 : 00 ,  3.49 MB/s]    49  merges.txt:  100 %|    ████████████████████████████████████████████████████████████████    ████████████████████████████████████████████████████████████████    ███████████████████████████████████████████████████████████ |    1.67 M/ 1.67 M [ 00 : 00 < 00 : 00 ,  2.77 MB/s]    50  added_tokens.json:  100 %|    ████████████████████████████████████████████████████████████████    ████████████████████████████████████████████████████████████████    ████████████████████████████████████████████████████████ |  265 / 265    [ 00 : 00 < 00 : 00 ,  3.35 MB/s]    51  special_tokens_map.json:  100 %|    ████████████████████████████████████████████████████████████████    ████████████████████████████████████████████████████████████████    ██████████████████████████████████████████████████ |  498 / 498    [ 00 : 00 < 00 : 00 ,  6.76 MB/s]    52  Special tokens have been added in the vocabulary, make sure the associated    word embeddings are fine-tuned or trained.    53  Special tokens have been added in the vocabulary, make sure the associated    word embeddings are fine-tuned or trained.    54  Setting `pad_token_id` to `eos_token_id`: 151645  for open-end generation.    55  User: Hello, who are you?    56  Assistant: I am an AI assistant whose name is InternVL, developed jointly by    Shanghai AI Lab and SenseTime.    57  Setting `pad_token_id` to `eos_token_id`: 151645  for open-end generation.    58  User: Can you tell me a story?    59  Assistant: Sure, here's a story:    60    61  Once upon a time, there was a young girl named Lily who lived in a small    village. She was a curious and adventurous girl who loved exploring the world    around her. One day, while wandering through the forest, she stumbled upon a    hidden cave. Excited by the prospect of discovering something new, she decided    to explore deeper into the cave.    62    63  As she entered the cave, she was amazed by the beauty of the surroundings. The    cave was filled with colorful flowers, sparkling crystals, and strange    creatures. Lily felt a sense of wonder and excitement as she explored the cave    further.    64    65  Suddenly, she heard a loud noise coming from the cave. She quickly turned    around and saw a group of angry creatures guarding the entrance. Lily was    scared, but she knew that she had to stay calm and find a way out.    66 67  She used her wits and skills to outsmart the creatures and escape the cave.    She made her way through the cave, dodging obstacles and avoiding traps.    Finally, she reached the exit and emerged from the cave safely.    68    69  As she looked back at the cave, Lily realized that she had discovered    something truly magical. She had discovered a world of wonder and adventure,    and she knew that she would always be fascinated by the mysteries of the world    around her.    70  Setting `pad_token_id` to `eos_token_id`: 151645  for open-end generation.    71  User: <image>    72  Please describe the image shortly.    73  Assistant: The image shows a red panda, a small, furry mammal known for its    distinctive red and white fur. The red panda is resting on a wooden structure,    possibly a platform or a bench, with its head leaning over the edge. The    animal's large, expressive eyes are looking directly at the camera, giving it    a curious and alert appearance. The background features a blurred natural    setting with greenery, suggesting that the photo was taken in a zoo or a    wildlife park.    74  Setting `pad_token_id` to `eos_token_id`: 151645  for open-end generation.    75  User: <image>    76  Please describe the image in detail.    77  Assistant: The image depicts a red panda, a small, intelligent mammal known    for its distinctive red and white fur. The red panda is characterized by its    large ears, which are covered in fur, and its large, expressive eyes. The    animal is resting on a wooden structure, which appears to be part of a wooden    enclosure, possibly a zoo or wildlife park. The background is blurred, but it    shows greenery, indicating that the setting is outdoors. The red panda's fur    is predominantly red, with white patches on its face, ears, and limbs. The    image captures the red panda in a relaxed and curious pose, with its eyes    looking directly at the camera.    78  Setting `pad_token_id` to `eos_token_id`: 151645  for open-end generation.    79  User: Please write a poem according to the image.    80  Assistant: In the forest's gentle embrace,    81  A red panda rests, serene and still,    82  Its fur a vivid red, its face a blaze,    83  A sight to behold, a marvel to see.    84    85  Its ears, large and round,    86  Covered with fur, a sight to see,    87  A blend of colors, a marvel to see,    88  A sight to behold, a marvel to see.    89    90  The background, blurred green,    91  Nature's canvas, a sight to see,    92  A peaceful sanctuary, a sight to see,    93  A sanctuary of life, a sight to see.    94 95  The red panda's eyes,    96  A soulful gaze, a sight to see,    97  A gentle presence, a sight to see,    98  A sight to behold, a sight to see.    99    100  In the forest's gentle embrace,    101  A red panda rests, serene and still,    102  A sight to behold, a marvel to see,    103  A sight to behold, a marvel to see.    104  Setting `pad_token_id` to `eos_token_id`: 151645  for open-end generation.    105  Setting `pad_token_id` to `eos_token_id`: 151645  for open-end generation.    106  User: What are the similarities and differences between these two images.    107  Assistant: The two images depict two different animals, but they share some    similarities and differences. Here are the key similarities and differences:    108    109  ### Similarities:    110  1.  **Species**: Both images feature a panda cub.    111  2.  **Location**: Both images are taken in a natural habitat, likely a zoo or    wildlife park.    112  3.  **Setting**: Both images show the panda resting on a wooden structure,    which is part of a larger enclosure.    113  4.  **Environment**: Both images have lush greenery, indicating a natural    habitat environment.    114    115  ### Differences:    116  1.  **Cub's Appearance**:    117  - **Cub in the first image**: The cub has a predominantly black and white    fur pattern, with a white face and black patches around the eyes and mouth.    118  - **Cub in the second image**: The cub has a similar appearance, with a    black and white fur pattern, but the background is more blurred, and the    setting appears to be a different environment.    119    120  2.  **Setting**:    121  - **First Image**: The cub is resting on a wooden structure, possibly part    of a larger enclosure.    122  - **Second Image**: The cub is in a more natural, less structured    environment, surrounded by greenery.    123    124  3.  **Behavior**:    125  - **First Image**: The cub appears to be resting or resting, with its eyes    looking directly at the camera.    126  - **Second Image**: The cub seems to be more relaxed, possibly resting or    exploring its surroundings.    127    128  4.  **Background**:    129  - **First Image**: The background is more natural and blurred, with    greenery and trees. 130  - **Second Image**: The background is more blurred, but it still shows    greenery, indicating a similar natural habitat.    131    132  These similarities and differences highlight the unique characteristics of    each panda cub, while also showcasing the natural habitat and environment in    which they are found.    133  Setting `pad_token_id` to `eos_token_id`: 151645  for open-end generation.    134  User: Image -1 : <image>    135  Image -2 : <image>    136  Describe the two images in detail.    137  Assistant: The two images provided are of pandas, a species of mammal native    to Asia. Both images depict pandas in their natural habitat, which appears to    be a zoo or a wildlife sanctuary.    138    139  ### Image -1 :    140  - **Panda**: The image features a young panda cub. The cub has a predominantly    white face with a black patch on its chest and a brownish-orange patch on its    back. The cub's eyes are dark and alert, and it has a small, round nose. The    cub is resting on a wooden structure, possibly a platform or a log, which is    part of a larger enclosure. The background shows greenery, indicating a    natural setting, likely a forest or a park.    141    142  ### Image -2 :    143  - **Panda**: The second image shows a larger panda cub, which appears to be a    juvenile. This panda cub is also predominantly white with black patches on its    face and back. It has a similar round nose and dark eyes. The cub is nestled    among green plants, suggesting it is in a more controlled environment,    possibly a zoo or a sanctuary. The background includes more greenery,    indicating a dense forest or a similar natural habitat.    144    145  Both images capture the adorable and endearing nature of pandas, highlighting    their social behavior and the natural environment they thrive in. The presence    of greenery and the natural habitat in both images emphasizes the importance    of preserving and protecting these endangered species.    146  Setting `pad_token_id` to `eos_token_id`: 151645  for open-end generation.    147  User: What are the similarities and differences between these two images.    148  Assistant: The two images of pandas provide a fascinating comparison of their    physical characteristics and the environments they are in. Here are the key    similarities and differences:    149    150  ### Similarities:    151  1.  **Species**: Both images depict pandas, a species of Asian rodent.    152  2.  **Physical Features**: Both pandas have a white face with black patches on    their back and chest, a characteristic feature of the species.    153  3.  **Cub Size**: The cub in both images is relatively small compared to the    adult panda, which is typical for juvenile pandas. 154  4.  **Habitat**: Both images show pandas in natural settings, likely in zoos or    wildlife sanctuaries.    155    156  ### Differences:    157  1.  **Size and Build**:    158  - The cub in Image -1  appears to be slightly larger than the juvenile in    Image -2.    159  - The adult panda in Image -1  has a more robust build, with a larger head    and a more pronounced facial structure.    160  2.  **Environment**:    161  - The cub in Image -1  is resting on a wooden structure, suggesting a more    controlled and human-influenced environment.    162  - The cub in Image -2  is nestled among green plants, indicating a more    natural and possibly more controlled habitat.    163  3.  **Behavioral Traits**:    164  - The cub in Image -1  seems to be more alert and possibly more active, as it    is resting.    165  - The cub in Image -2  appears more relaxed and comfortable, possibly    indicating a more natural or less controlled environment.    166  4.  **Cub Behavior**:    167  - The cub in Image -1  seems to be more curious and possibly more active, as    it is resting.    168  - The cub in Image -2  appears more docile and possibly more comfortable in    its natural habitat.    169    170  ### Conclusion:    171  - The primary similarity between the two images is the presence of pandas, a    species that is native to Asia.    172  - The differences lie in the size, build, and the environments they are in.    The cub in Image -1  appears to be larger and more human-influenced, while the    cub in Image -2  seems to be in a more natural, possibly controlled habitat.    173  Setting `pad_token_id` to `eos_token_id`: 151645  for open-end generation.    174  User: <image>    175  Describe the image in detail.    176  Assistant: The image features a young red panda, a popular and beloved species    of animal. The red panda has a striking appearance with a predominantly red    face, a white underbelly, and a black nose. Its fur is thick and fluffy, with    a mix of red and white fur, particularly around the face, ears, and limbs. The    red panda's eyes are large and expressive, with a black pupil and a white ring    around the iris, giving it a distinctive and endearing look.    177    178  The red panda is resting on a wooden structure, which appears to be part of a    wooden enclosure or cage. The background is blurred but shows greenery,    indicating that the red panda is likely in a natural or semi-natural habitat.    The lighting in the image is soft and natural, suggesting that the photo was    taken outdoors in daylight. The red panda's posture is relaxed, with its head resting on the wooden structure, and it appears to be looking directly at the    camera with a curious and gentle expression.    179  User: <image>    180  Describe the image in detail.    181  Assistant: The image depicts a cute, black-and-white panda cub sitting amidst    lush greenery. The panda is nestled among bamboo stalks, which are a common    habitat for pandas. The cub appears to be in a relaxed state, with its front    paws resting on the bamboo stalks and its head slightly tilted upwards. The    panda's large, expressive eyes are wide open, and it seems to be looking    directly at the camera with a curious and gentle expression.    182    183  The background is filled with various green plants and foliage, creating a    natural and serene environment. The ground is covered with a mix of grass and    small plants, which adds to the overall tranquil atmosphere of the scene. The    lighting in the image suggests it is daytime, with natural light illuminating    the scene and highlighting the vibrant colors of the panda and its    surroundings.    ⽅法2:离线⽅式获得    前提条件    1.  安装了 Docker 的系统。    2.  可以通过 USB 驱动器、⽹络共享或其他⽅法传输⽂件的⼿段。    3.  cuda>=11.8    步骤 1:在本地机器上加载 Docker 镜像    1.  确保 Docker 已安装:    在终端中输⼊以下命令以确认 Docker 已安装:    1  docker --version    2.  将镜像压缩包  internvl_v2.tar  拷⻉到本地机器:    3.  加载 Docker 镜像:    在终端中运⾏以下命令将镜像加载到 Docker 中,此命令会从  internvl_v2 .tar  ⽂件中加载    Docker 镜像,并将其添加到本地 Docker 镜像库中: 1  docker load -i  internvl_v2 .tar    4.  确认镜像已加载:    使⽤以下命令列出所有本地 Docker 镜像,以确认镜像已成功加载:    1  docker images    您应该能够看到⼀个新的镜像,例如:    1  REPOSITORY TAG IMAGE ID CREATED    SIZE    2  qishisuren/internvl v2 e32384490a23 2 days ago    16.6GB    步骤 2:运⾏Docker容器    同⽅法1    输出    同⽅法1    ⽅法3:⾃主构建镜像    前提条件    1.  安装了 Docker 的系统。    2.  可以通过 USB 驱动器、⽹络共享或其他⽅法传输⽂件的⼿段。    3.  cuda>=11.8    4.  已复制项⽬⽂件到本地:    1  git clone https: //github.com/OpenGVLab/InternVL.git   Dockerfile    1  FROM nvidia/cuda: 11.8.0 -cudnn8-devel-ubuntu22 .04 2    3  WORKDIR /InternVL    4    5  #  设置代理环境变量(如有必要)    6  ENV http_proxy= \    7  https_proxy= \    8  HTTP_PROXY= \    9  HTTPS_PROXY    10    11  #  安装系统依赖项和  Python  包    12  RUN apt-get update && apt-get install -y \    13  git \    14  wget \    15  python3-pip \    16  && apt-get clean \    17  && rm -rf /var/lib/apt/lists /*   18    19  # 设置 CUDA_HOME 环境变量   20  ENV CUDA_HOME=/usr/local/cuda   21  ENV PATH=$CUDA_HOME/bin:$PATH   22  ENV LD_LIBRARY_PATH=$CUDA_HOME/lib64:$LD_LIBRARY_PATH   23    24  # 复制应⽤程序代码到⼯作⽬录   25  COPY . .   26  # 或从 GitHub 克隆指定仓库   27  # RUN git clone https://github.com/OpenGVLab/InternVL.git   28    29  # 进⼊仓库⽬录   30  WORKDIR /InternVL   31    32  # 安装 Python   33  # 注意:⼿动删除 internvl_chat.txt flash-attn 字段   34  RUN pip3 install --no-cache-dir packaging \   35  && pip3 install --no-cache-dir -r ./requirements/internvl_chat.txt \   36  && pip3 install -U flash-attn --no-build-isolation   37    38  # 设置默认环境变量   39  ENV CUDA_DEVICE=4   40  ENV MODEL_PATH='OpenGVLab/InternVL2-1B'   41    42  # 进⼊到 /internvl_chat ⽂件夹   43  WORKDIR ./internvl_chat   44    45  # 运⾏你的应⽤程序   46  CMD ["python3", "../run.py"] 步骤 1:构建 Docker 镜像    ⾸先,在有互联⽹连接的机器上构建 Docker 镜像。    1.  确保 Dockerfile 在当前⽬录:    1  ls    2  Dockerfile    2.  构建 Docker 镜像:    1  docker build -t yourusername/internvl:latest .    步骤 2:运⾏Docker容器    同⽅法1    输出    同⽅法1

Read more

深入理解 Proxy 和 Object.defineProperty

在JavaScript中,对象是一种核心的数据结构,而对对象的操作也是开发中经常遇到的任务。在这个过程中,我们经常会使用到两个重要的特性:Proxy和Object.defineProperty。这两者都允许我们在对象上进行拦截和自定义操作,但它们在实现方式、应用场景和灵活性等方面存在一些显著的区别。本文将深入比较Proxy和Object.defineProperty,包括它们的基本概念、使用示例以及适用场景,以帮助读者更好地理解和运用这两个特性。 1. Object.defineProperty 1.1 基本概念 Object.defineProperty 是 ECMAScript 5 引入的一个方法,用于直接在对象上定义新属性或修改已有属性。它的基本语法如下: javascript 代码解读复制代码Object.defineProperty(obj, prop, descriptor); 其中,obj是目标对象,prop是要定义或修改的属性名,descriptor是一个描述符对象,用于定义属性的特性。 1.2 使用示例 javascript 代码解读复制代码//

By Ne0inhk

Proxy 和 Object.defineProperty 的区别

Proxy 和 Object.defineProperty 是 JavaScript 中两个不同的特性,它们的作用也不完全相同。 Object.defineProperty 允许你在一个对象上定义一个新属性或者修改一个已有属性。通过这个方法你可以精确地定义属性的特征,比如它是否可写、可枚举、可配置等。该方法的使用场景通常是需要在一个对象上创建一个属性,然后控制这个属性的行为。 Proxy 也可以用来代理一个对象,但是相比于 Object.defineProperty,它提供了更加强大的功能。使用 Proxy 可以截获并重定义对象的基本操作,比如访问属性、赋值、函数调用等等。在这些操作被执行之前,可以通过拦截器函数对这些操作进行拦截和修改。因此,通过 Proxy,你可以完全重写一个对象的默认行为。该方法的使用场景通常是需要对一个对象的行为进行定制化,或者需要在对象上添加额外的功能。 对比 以下是 Proxy 和 Object.defineProperty 的一些区别对比: 方面ProxyObject.defineProperty语法使用 new Proxy(target,

By Ne0inhk