Skip to content

对象

一句话解释

对象是 集合的 键-值 pairs 那个分组 related 数据 and behavior under 单个 name.

用大白话说

对象是 如容器使用 labeled compartments. 每个 compartment (键) 持有值, and 你 use label 到查找什么是 内部. 例如, person 对象可能有 name 键持有 "Ada" and age key holding 36.

Objects are the primary way to represent real-world entities in code. Instead of having separate variables personName, personAge, personEmail, you group them into one person object with properties name, age, email.

In JavaScript, objects are created with curly braces and use string keys. In Python, the equivalent is a dictionary (dict). In Java, you define a class and create instances. The concept is the same: named properties grouping related data.

示例

javascript
const person = {
  name: "Ada",
  age: 36,
  email: "[email protected]"
};

console.log(person.name);  // "Ada"
console.log(person.age);   // 36

person 对象有 three 属性. 你 access 每个值 using 点 notation 使用键 name.

常见混淆

  • 容易混淆的对象: 数组

    关键区别: 对象 uses named 键到 access 值; 数组 uses numeric 索引. 对象是 for named 属性; 数组是 for 有序列表.

  • 容易混淆的对象: 类

    关键区别: 类是 blueprint/template for 创建对象. 对象是 特定实例创建从 类 (or 创建 directly as literal).

相关术语

相关资源

相关课程

  • 对象

    学习如何对象工作 in programming.

解读错误信息

用大白话解释常见错误——什么意思、为什么发生、如何修复。

查看错误

← 返回术语表