什么是 "Something { key: value, SomethingElse { key: value, ...}}" 结构?
What is a "Something { key: value, SomethingElse { key: value, ...}}" structure?
我正在尝试建立一个博客,其中包含 Hexo, using Pug as the templating engine. I do not understand 如何访问全局变量(在 Hexo 中定义)并最终添加了一些 JavaScript 来调试输出。
在 Hexo 中,site
变量保存有关正在使用的站点的信息。这是一个 JavaScript 强大的静态博客生成器,可以在处理过程中注入 JS。我希望在处理模板时在控制台上输出 site
变量(_
是 Lodash 的全局变量):
_.forEach(site, function (po) {
console.log('post info', po)
})
我得到的输出是(我分解了 post info
块):
post info Query {
data:
[ Document {
title: 'first article',
layout: 'mypost',
_content: '\nThis is the first article',
source: '_posts/first.md',
raw: '---\ntitle: first article\ntags: tech\nlayout: mypost\n---\n\nThis is the first article',
slug: 'first',
published: true,
date: moment("2018-02-20T20:57:27.120"),
updated: moment("2018-02-22T09:19:24.597"),
comments: true,
photos: [],
link: '',
_id: 'cjdy8m62w00005ondnc5md94c',
content: '<p>This is the first article</p>\n',
site: [Object],
excerpt: '',
more: '<p>This is the first article</p>\n',
path: [Getter],
permalink: [Getter],
full_source: [Getter],
asset_dir: [Getter],
tags: [Getter],
categories: [Getter],
prev: [Object],
__post: true,
lang: null,
canonical_path: '2018/02/20/first/index.html' },
Document {
title: 'Hello World 2',
_content: '\nSecond article comes here',
source: '_posts/second.md',
raw: '---\ntitle: Hello World 2\ntags: tech\n---\n\nSecond article comes here',
slug: 'second',
published: true,
date: moment("2018-02-20T23:05:52.156"),
updated: moment("2018-02-22T09:19:48.205"),
comments: true,
layout: 'post',
photos: [],
link: '',
_id: 'cjdy8m63300015ond87428rhr',
content: '<p>Second article comes here</p>\n',
site: [Object],
excerpt: '',
more: '<p>Second article comes here</p>\n',
path: [Getter],
permalink: [Getter],
full_source: [Getter],
asset_dir: [Getter],
tags: [Getter],
categories: [Getter],
next: [Object],
__post: true,
lang: null,
canonical_path: '2018/02/20/second/index.html' } ],
length: 2 }
post info Query { data: [], length: 0 }
post info Model {
domain: null,
_events: {},
_eventsCount: 0,
_maxListeners: undefined,
name: 'Category',
data: {},
_mutex: Mutex { _locked: false, _queue: [] },
schema:
Schema {
paths:
{ name: [Object],
parent: [Object],
slug: [Object],
path: [Object],
permalink: [Object],
posts: [Object],
length: [Object],
_id: [Object] },
statics: {},
methods: {},
hooks: { pre: [Object], post: [Object] },
stacks:
{ getter: [Array],
setter: [Array],
import: [Array],
export: [Array] } },
length: 0,
Document: { [Function] super_: [Function: Document] },
Query: { [Function] super_: [Function: Query] } }
post info Model {
domain: null,
_events: {},
_eventsCount: 0,
_maxListeners: undefined,
name: 'Tag',
data:
{ cjdy8m63600025ondq69zill9: { name: 'tech', _id: 'cjdy8m63600025ondq69zill9' } },
_mutex: Mutex { _locked: false, _queue: [] },
schema:
Schema {
paths:
{ name: [Object],
slug: [Object],
path: [Object],
permalink: [Object],
posts: [Object],
length: [Object],
_id: [Object] },
statics: {},
methods: {},
hooks: { pre: [Object], post: [Object] },
stacks:
{ getter: [Array],
setter: [Array],
import: [Array],
export: [Array] } },
length: 1,
Document: { [Function] super_: [Function: Document] },
Query: { [Function] super_: [Function: Query] } }
post info {}
我不知道 Query
、Model
、Schema
和 Document
是什么,以及如何访问其中的数据。
其中任何一个后面的内容似乎是一个对象(键和值由冒号分隔),但它还包含诸如
之类的结构
schema:
Schema {
paths:
{ name: [Object],
(...)
我不明白(特别是 Schema {
部分)。
这是什么类型的数据结构以及如何访问其内容?
这些实体是Javascript classes。
当一个 class 实例被记录到浏览器控制台时,它的 class 名称被保留,这就是为什么好的命名通常对调试非常有用的部分原因。请参阅以下示例:
class Foo {
// Define methods and properties
}
const instance = new Foo();
// Will log `{}` in the snippet console, but `Foo {}` in the browser console.
console.log(instance);
我正在尝试建立一个博客,其中包含 Hexo, using Pug as the templating engine. I do not understand 如何访问全局变量(在 Hexo 中定义)并最终添加了一些 JavaScript 来调试输出。
在 Hexo 中,site
变量保存有关正在使用的站点的信息。这是一个 JavaScript 强大的静态博客生成器,可以在处理过程中注入 JS。我希望在处理模板时在控制台上输出 site
变量(_
是 Lodash 的全局变量):
_.forEach(site, function (po) {
console.log('post info', po)
})
我得到的输出是(我分解了 post info
块):
post info Query {
data:
[ Document {
title: 'first article',
layout: 'mypost',
_content: '\nThis is the first article',
source: '_posts/first.md',
raw: '---\ntitle: first article\ntags: tech\nlayout: mypost\n---\n\nThis is the first article',
slug: 'first',
published: true,
date: moment("2018-02-20T20:57:27.120"),
updated: moment("2018-02-22T09:19:24.597"),
comments: true,
photos: [],
link: '',
_id: 'cjdy8m62w00005ondnc5md94c',
content: '<p>This is the first article</p>\n',
site: [Object],
excerpt: '',
more: '<p>This is the first article</p>\n',
path: [Getter],
permalink: [Getter],
full_source: [Getter],
asset_dir: [Getter],
tags: [Getter],
categories: [Getter],
prev: [Object],
__post: true,
lang: null,
canonical_path: '2018/02/20/first/index.html' },
Document {
title: 'Hello World 2',
_content: '\nSecond article comes here',
source: '_posts/second.md',
raw: '---\ntitle: Hello World 2\ntags: tech\n---\n\nSecond article comes here',
slug: 'second',
published: true,
date: moment("2018-02-20T23:05:52.156"),
updated: moment("2018-02-22T09:19:48.205"),
comments: true,
layout: 'post',
photos: [],
link: '',
_id: 'cjdy8m63300015ond87428rhr',
content: '<p>Second article comes here</p>\n',
site: [Object],
excerpt: '',
more: '<p>Second article comes here</p>\n',
path: [Getter],
permalink: [Getter],
full_source: [Getter],
asset_dir: [Getter],
tags: [Getter],
categories: [Getter],
next: [Object],
__post: true,
lang: null,
canonical_path: '2018/02/20/second/index.html' } ],
length: 2 }
post info Query { data: [], length: 0 }
post info Model {
domain: null,
_events: {},
_eventsCount: 0,
_maxListeners: undefined,
name: 'Category',
data: {},
_mutex: Mutex { _locked: false, _queue: [] },
schema:
Schema {
paths:
{ name: [Object],
parent: [Object],
slug: [Object],
path: [Object],
permalink: [Object],
posts: [Object],
length: [Object],
_id: [Object] },
statics: {},
methods: {},
hooks: { pre: [Object], post: [Object] },
stacks:
{ getter: [Array],
setter: [Array],
import: [Array],
export: [Array] } },
length: 0,
Document: { [Function] super_: [Function: Document] },
Query: { [Function] super_: [Function: Query] } }
post info Model {
domain: null,
_events: {},
_eventsCount: 0,
_maxListeners: undefined,
name: 'Tag',
data:
{ cjdy8m63600025ondq69zill9: { name: 'tech', _id: 'cjdy8m63600025ondq69zill9' } },
_mutex: Mutex { _locked: false, _queue: [] },
schema:
Schema {
paths:
{ name: [Object],
slug: [Object],
path: [Object],
permalink: [Object],
posts: [Object],
length: [Object],
_id: [Object] },
statics: {},
methods: {},
hooks: { pre: [Object], post: [Object] },
stacks:
{ getter: [Array],
setter: [Array],
import: [Array],
export: [Array] } },
length: 1,
Document: { [Function] super_: [Function: Document] },
Query: { [Function] super_: [Function: Query] } }
post info {}
我不知道 Query
、Model
、Schema
和 Document
是什么,以及如何访问其中的数据。
其中任何一个后面的内容似乎是一个对象(键和值由冒号分隔),但它还包含诸如
之类的结构schema:
Schema {
paths:
{ name: [Object],
(...)
我不明白(特别是 Schema {
部分)。
这是什么类型的数据结构以及如何访问其内容?
这些实体是Javascript classes。
当一个 class 实例被记录到浏览器控制台时,它的 class 名称被保留,这就是为什么好的命名通常对调试非常有用的部分原因。请参阅以下示例:
class Foo {
// Define methods and properties
}
const instance = new Foo();
// Will log `{}` in the snippet console, but `Foo {}` in the browser console.
console.log(instance);