如何停止Coffeescript从转义的关键字? [英] How to stop Coffeescript from escaping keywords?

查看:293
本文介绍了如何停止Coffeescript从转义的关键字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想写一个indexeddb函数delete。它应该在JS中读取:

I am trying to write a indexeddb function "delete". It should read like this in JS:

var transaction = db.transaction('objectStore','readwrite');
var objectStore = transaction.objectStore('objectStore');
objectStore.delete(id);

但是,当我写在CS:

transaction = db.transaction 'objectStore','readWrite'
objectStore = transaction.objectStore 'objectStore'
objectStore.delete(id)

当然会输出:

...
objectStore["delete"](id);

我没有为IDBTransaction写一个名为delete的方法,但是我必须使用它。如何让CS避免转换删除方法并将其转换为对象中的删除键?

I didn't write a method for IDBTransaction called "delete", but I have to use it. How can I keep CS from escaping the "delete" method and turning it into a "delete" key in an object?

推荐答案

使用反引号传递裸露的Javascript:

Use backticks to pass through bare Javascript:

`objectStore.delete(id)`

将通过逐字编译。请在我最喜欢的网站上尝试在CS和JS之间进行解释: http://js2coffee.org/#coffee2js

will be compiled through verbatim. Try it here at my favorite site for interpreting between CS and JS: http://js2coffee.org/#coffee2js

transaction = db.transaction 'objectStore','readWrite'
objectStore = transaction.objectStore 'objectStore'
`objectStore.delete(id)`

成为

var objectStore, transaction;

transaction = db.transaction('objectStore', 'readWrite');

objectStore = transaction.objectStore('objectStore');

objectStore.delete(id);

这篇关于如何停止Coffeescript从转义的关键字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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