Object::pr = -> console.log eval("'"+@+"'").toString() console.log '____________________________' @ # 'hello.coffee'.pr() Object::classGet = -> this.constructor.name.toString() 

There is a classGet () method.

It is called like this.

 [].classGet().pr() 

And he is called like this.

 (do [].classGet).pr() 

How to rewrite the classGet method to call it like this

 [].classGet.pr() 

or so

 [].classGet.pr 
  • Some features of the language have to be tolerated, and if it requires the function to call parentheses, then nothing can be done about it. One could try to do this via get / set on a property, but not for an already existing class without the possibility of overriding and would be a highly ineffective solution. - Alex Krass
  • Please comment on this `Object :: pr = -> console.log eval (" '"+ @ +"' "). ToString () console.log '____________________________' @ stringCreate = (s) -> new String s Function :: property = (prop, desc) -> Object.defineProperty @prototype, prop, desc class String constructor: (@s) -> @property 'classGet', get: -> @ s.constructor.name.toString () stringCreate (''). classGet.pr () ` - user228363

0