ES6引入了一系列方便的"语法糖".其中包括JavaScript函数的默认参数功能以及rest参数.每当试图在rest参数上设置默认参数值时,我发现我的控制台(或devTools)会抱怨(即抛出错误).我发现在其他地方很少引用这个特定的问题,我想知道是否1.)它可以这样做2.)为什么不(假设它不可能).
作为一个例子,我设计了一个微不足道的(但希望仍然有目的)的例子.在函数的第一次迭代中,我构造了函数,使其可以工作(也就是说,不给rest参数一个默认值).
const describePerson = (name, ...traits) => `Hi, ${name}! You are ${traits.join(', ')}`;
describePerson('John Doe', 'the prototypical placeholder person');
// => "Hi, John Doe! You are the prototypical placeholder person"
Run Code Online (Sandbox Code Playgroud)
但是,现在使用默认值:
const describePerson = (name, ...traits = ['a nondescript individual']) => `Hi, ${name}! You are ${traits.join(', ')}`;
describePerson('John Doe');
// => Uncaught SyntaxError: Unexpected token =
Run Code Online (Sandbox Code Playgroud)
任何帮助是极大的赞赏.
我们在工作地点使用Yammer,我们正在寻找一种以自定义方式对组进行排序的方法.为此,如果我们可以向当前存在的所有组添加自定义元数据,这将非常有用.有没有明确定义的方式,或者,如果没有,是否有方法在Yammer 中实现自定义排序(即,根据我们自己定义的标准)?任何帮助是极大的赞赏.谢谢!
我正在尝试使用 Homebrew 为应用程序项目安装 Redis。Homebrew IS 已安装并已更新至最新版本。但是,当我$ brew install redis从终端运行时,我总是遇到相同的错误消息,在下面重新发布。
\xe2\x9e\x9c ~ git:(master) \xe2\x9c\x97 brew install redis\nWarning: You are using OS X 10.12.\nWe do not provide support for this pre-release version.\nYou may encounter build failures or other breakages.\nPlease create pull-requests instead of filing issues.\n==> Downloading http://download.redis.io/releases/redis-3.2.3.tar.gz\nAlready downloaded: /Users/oliverisenrich/Library/Caches/Homebrew/redis-3.2.3.tar.gz\n==> make install PREFIX=/usr/local/Cellar/redis/3.2.3 CC=clang\nLast 15 lines from /Users/oliverisenrich/Library/Logs/Homebrew/redis/01.make:\n#include <stdio.h>\n ^\nmake[1]: *** [ae.o] Error 1\nmake[1]: *** [anet.o] Error 1\n1 error generated.\n1 error generated.\n1 error generated.\nmake[1]: *** [dict.o] Error 1\nmake[1]: *** [zmalloc.o] …Run Code Online (Sandbox Code Playgroud) JavaScript语言的内置全局对象的文档Object说明了这一点
Object.length
值为1.
这个属性有什么意义,另外,为什么object.length我们不能以同样的方式获得这个属性array.length?
乍一看,在我看来,后一个问题的原因与length对象属性的解释器中的可能混淆有关属性访问/初始化的点符号方法.
在package.json内部,通常通过包含文件路径(相对于项目的根目录)作为 field 的值来指定模块的主要(或main )入口点。main
同样,还有field ,它scripts是一个字典,其键是关键字,允许运行在终端内作为其值传递的关联命令。一种常见的脚本允许您运行 Node 或Nodemon。为了便于说明,这里有一个package.json配置示例:
{
"name": "example",
"version": "1.0.0",
"description": "Example package.json for StackOverflow question",
"main": "index.js",
"scripts": {
"dev": "nodemon index.js"
},
"author": "IsenrichO",
"license": "ISC",
"dependencies": {
"express": "^4.13.4",
"nodemon": "^1.9.1"
}
}
Run Code Online (Sandbox Code Playgroud)
您会注意到dev上面的脚本命令在index.js文件上运行Nodemon。该文件也是字段中指定的应用程序的入口点。main
那么我的问题是:是否可以引用您的其中一个中的package.json的密钥指定的文件?换句话说,人们可以写一些类似的东西吗?mainscripts
"scripts": {
"dev": "nodemon main"
}
Run Code Online (Sandbox Code Playgroud)
这看似迂腐,但却是一个真正的问题。感谢所有帮助!
javascript ×3
ecmascript-6 ×1
homebrew ×1
json ×1
metadata ×1
node.js ×1
npm ×1
object ×1
oop ×1
package.json ×1
redis ×1
sorting ×1
terminal ×1
yammer ×1