How does this object method definition work without the “function” keyword?

How is it possible that this runs at all in any browser? Is is some sort of new ES6 functionality? Yes. … Method definitions A property of an object can also refer to a function or a getter or setter method. var o = { property: function ([parameters]) {}, get property() {}, set property(value) {}, … Read more

Try/catch oneliner available?

You could use the following function and then use that to oneline your try/catch. It’s use would be limited and makes the code harder to maintain so i’ll never use it. var v = tc(MyTryFunc, MyCatchFunc); tc(function() { alert(‘try’); }, function(e) { alert(‘catch’); }); /// try/catch function tc(tryFunc, catchFunc) { var val; try { val … Read more

Other Ruby Map Shorthand Notation

Unfortunately this shorthand notation (which calls “Symbol#to_proc”) does not have a way to pass arguments to the method or block being called, so you couldn’t even do the following: array_of_strings.map(&:include, ‘l’) #=> this would fail BUT, you are in luck because you don’t actually need this shortcut to do what you are trying to do. … Read more