For instance can a write a function using
ಠ(){}
instead of
function(){}
Note: ಠ is a valid identifier according to ECMAScript 6 / Unicode 8.0.0.
For instance can a write a function using
ಠ(){}
instead of
function(){}
Note: ಠ is a valid identifier according to ECMAScript 6 / Unicode 8.0.0.
https://mothereff.in/js-variables
- 2 You're asking if you can change the language's keywords? – Dave Newton Commented Aug 6, 2015 at 18:22
-
5
function
is not an identifier. – loganfsmyth Commented Aug 6, 2015 at 18:22 -
You can certainly do the following:
var ಠ = function(){};
. – DRD Commented Aug 6, 2015 at 18:23 - or create an alias for them? – Bryan Grace Commented Aug 6, 2015 at 18:23
3 Answers
Reset to default 6No, you cannot.
You might be able to use something like Sweet or another JS transpiler.
The logical question that nobody has asked yet is why? My first reaction is that this is an X/Y problem, since function
doesn't seem particularly onerous on its own.
The closest thing you can do is alias the Function
constructor:
var ಠ = Function;
But that won't let you define functions in exactly the same way, the usage would be:
ಠ("arg1","arg2","alert('function body');if(typeof(ಠ) !== 'undefined')alert('you\'ve done a very bad thing');");
You probably shouldn't do this, though, unless you're going for some sort of golf challenge, obfuscation shenanigans, or you're making a small joke site and want to make it harder (or more amusing) for people to read your code. Don't do this for anything serious. Please.
If you don't like function(){}
you can use an arrow function in ES6.
Disclaimer: arrow functions lexically bind the
this
value
var add = function(x,y) { return x + y; };
Can be written as
let add = (x,y) => x + y;
It's significantly less verbose when you start nesting functions too
var add = function(x) {
return function(y) {
return x + y;
};
};
Can be written as
let add = x => y => x + y;
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744347750a4569790.html
评论列表(0条)