此方法调用如何工作

How does this method call work?

本文关键字:工作 何工作 调用 此方法      更新时间:2023-09-26

我在 NodeJS 中使用PDFKit将一些图像添加到 PDF 文档中。其中一个例子是这样的:

# Fit the image within the dimensions
doc.image('images/test.jpeg', 320, 15, fit: [100, 100])
   .rect(320, 15, 100, 100)
   .stroke()
   .text('Fit', 320, 0)  

我使用的是纯JS而不是咖啡脚本,我不明白第一行是如何工作的。键值对如何作为参数传入,JS等效项是什么?

文档在这里: http://pdfkit.org/docs/images.html

这是JavaScript的等效物

doc.image('images/test.jpeg', 320, 15, {
  fit: [100, 100]
}).rect(320, 15, 100, 100).stroke().text('Fit', 320, 0);

在许多情况下,咖啡对象不需要大括号。 查看 http://js2.coffee/在咖啡和香草 JavaScript 之间来回转换