Details
-
Type:
Enhancement
-
Status:
Resolved
-
Priority:
Critical
-
Resolution: Completed
-
Affects Version/s: None
-
Fix Version/s: None
-
Component/s: None
-
Labels:None
Description
Currently ClojureScript provides the following dot access syntaxes:
(.p o) ;=> a property access (.m o <args>) ;=> a method call (. o p) ;=> a property access (. o p <args>) ;=> a method call (. o (m)) ;=> a method call (. o (m <args>)) ;=> a method call
This is potentially confusing. Especially considering that Clojure looks as follows:
(.p o) ;=> a property access if p is a property (.p o) ;=> a method call if p is a method (.m o <args>) ;=> a method call (. o p) ;=> a property access if p is a property (. o p) ;=> a method call if p is a method (. o p <args>) ;=> a method call (. o (m)) ;=> a method call (. o (m <args>)) ;=> a method call
The divergence between the Clojure and ClojureScript way is due to first-class functions. That is, in JavaScript a property can be a field or a function or a method. There is currently no way to distinguish between the desire to call a method and retrieve a function as a property except through syntax. This ticket would shorten the gap between Clojure and ClojureScript in the following way (ClojureScript proposal below):
(.m o) ;=> a method call (.m o <args>) ;=> a method call (. o m) ;=> a method call (. o m <args>) ;=> a method call (. o (m)) ;=> a method call (. o (m <args>)) ;=> a method call (.-p o) ;=> a property access (. o -p) ;=> a property access
This would be a breaking change, but would shorten the divergence between Clojure and ClojureScript.