Syntax check in js2-mode is awesome.
But sometimes I just want to define a function named "delete" or "new" even thought that's not a good idea. Js2-mode seems to treat this as an error.
How can I use build-in keywords as function name in js2-mode? I need your help.
================================================
I am sorry for my stupid question...
I'm using etags.
but writing someting like:
exports.new = function() {
};
seems etags will treat this as the definition of 'exports.new', not 'new'.
TAGS
};exports.new248,8614
So I'm trying to write something like:
function new() {
}
exports.new = new;
How stupid I am !!!
So my questiong turn back to how to make etags find the definition of 'new', not 'exports.new' ?
Thanks. :)
"Js2-mode seems to treat this as an error"
It is an error, isn't it?
I really don't understand why you'd want to do it, but the following works:
someObject["new"] = function() {
alert("This is the 'new' function.");
}
someObject["new"]();
Assuming someObject
already exists as an object. Or:
var someObject = {
"new" : function() {},
"delete" : function() {}
};
someObject["new"]();
someObject["delete"]();
In the browser you can say window["new"] = function() {}
, but you can't call the resulting function with new()
, you have to say window["new"]()
.
In node.js I believe the equivalent would be global["new"] = function() {}
. I don't use node, but I assume this would create a global function called "new", but you wouldn't be able to call it with the new()
syntax, you'd have to say global["new"]()
.
I do not recommend doing this.