空方括号在javascript中表示为变量值是什么? [英] What does empty square brackets represent as a variable value in javascript?

查看:78
本文介绍了空方括号在javascript中表示为变量值是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道下面的代码中的两个变量(被邀请,rsvps)中的空方括号是做什么的.

I'm wondering what do those empty square brackets do in those two variables (invited, rsvps) in the code below.

Parties.insert({
  _id: id,
  owner: this.userId,
  x: options.x,
  y: options.y,
  title: options.title,
  description: options.description,
  public: !! options.public,
  invited: [],
  rsvps: [],
  likes: 0,
});

推荐答案

[]new Array()的简写.它通常比new Array()高,因为它对JavaScript引擎更轻巧.

[] is shorthand for new Array(). Its often prevert above new Array() because its more lightweight for the JavaScript engine.

使用new Array(),引擎必须向上作用域链才能找到构造函数.而且此构造函数可能已被覆盖或操纵.

With new Array() the engine has to go up the scope chain to find the constructor. And this constructor could have been overwritten or manipulated.

这篇关于空方括号在javascript中表示为变量值是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆