import{_ as i}from"./plugin-vue_export-helper-DlAUqK2U.js";import{c as a,a as t,o as h}from"./app-zNUiodpH.js";const n={};function l(k,s){return h(),a("div",null,[...s[0]||(s[0]=[t(`
JavaScript中的对象(object)用于存储各种键值集合和更复杂的实体。例如下面的对象
var person = {
firstName: 'John',
lastName: 'Doe',
age: 30,
isStudent: false,
greet: function() {
console.log('Hello, I am ' + this.firstName + ' ' + this.lastName);
}
print_name() {
console.log(lastName + ' ' + firstName)
}
};
如何使用对象
console.log(person.firstName); // 输出: John
person.greet(); // 输出: Hello, I am John Doe
javascript中的类(class)是用于创建对象的模板,和c++中的类相似,但是需要在constructor()函数中声明类成员
class User {
constructor(name) {
this.name = name;
}
greet() {
console.log("Hello, I'm " + this.name)
}
}
使用方法
var user = new User("Alice")
user.greet()
`,11)])])}const r=i(n,[["render",l]]),d=JSON.parse('{"path":"/note/language/javascript/object_and_class.html","title":"对象和类","lang":"zh-CN","frontmatter":{"description":"对象和类 对象 JavaScript中的对象(object)用于存储各种键值集合和更复杂的实体。例如下面的对象 如何使用对象 类 javascript中的类(class)是用于创建对象的模板,和c++中的类相似,但是需要在constructor()函数中声明类成员 使用方法","head":[["script",{"type":"application/ld+json"},"{\\"@context\\":\\"https://schema.org\\",\\"@type\\":\\"Article\\",\\"headline\\":\\"对象和类\\",\\"image\\":[\\"\\"],\\"dateModified\\":\\"2025-02-22T14:42:02.000Z\\",\\"author\\":[{\\"@type\\":\\"Person\\",\\"name\\":\\"JinChao\\",\\"url\\":\\"https://thecodeway.com\\"}]}"],["meta",{"property":"og:url","content":"https://thejinchao.github.io/note/language/javascript/object_and_class.html"}],["meta",{"property":"og:site_name","content":"我的博客和笔记"}],["meta",{"property":"og:title","content":"对象和类"}],["meta",{"property":"og:description","content":"对象和类 对象 JavaScript中的对象(object)用于存储各种键值集合和更复杂的实体。例如下面的对象 如何使用对象 类 javascript中的类(class)是用于创建对象的模板,和c++中的类相似,但是需要在constructor()函数中声明类成员 使用方法"}],["meta",{"property":"og:type","content":"article"}],["meta",{"property":"og:locale","content":"zh-CN"}],["meta",{"property":"og:updated_time","content":"2025-02-22T14:42:02.000Z"}],["meta",{"property":"article:modified_time","content":"2025-02-22T14:42:02.000Z"}]]},"git":{"createdTime":1740235322000,"updatedTime":1740235322000,"contributors":[{"name":"thejinchao","username":"thejinchao","email":"thejinchao@gmail.com","commits":1,"url":"https://github.com/thejinchao"}]},"readingTime":{"minutes":0.51,"words":154},"filePathRelative":"note/language/javascript/object_and_class.md","autoDesc":true}');export{r as comp,d as data};