I want to replace this.
with @
sign like in coffee script. I've write the macro:
macro (@) {
case { return $a } => { return this.$a }
}
function LogSmth(name) {
this.name = name;
console.log(@name);
}
But got
SyntaxError: [macro] Macro `@` could not be matched with `name...`
57: console.log(@name);
How to fix this?
Allow me to expand on Mike C's answer. What happens if we try and do something just with
@
(a common operation is to bind an object tothis
). One might write:X.bind(@, ...)
but this would fail with the above macro. Another possibility is the ability to do this:@['some property with a weird name']
, but this would also fail with the above macro.Here's my version:
This also exposes one useful property about applying rules to macros which is that order matters.