Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Experiment with returning function expressions / closures as init() return for simpler modules #19

Open
jfrux opened this issue Sep 28, 2012 · 3 comments

Comments

@jfrux
Copy link
Contributor

jfrux commented Sep 28, 2012

This would provide a seemless interface for simple modules.
If a module has a single utility function then it could simply do

component name="say_something" {
   public any function init() {
         return function(arg1,arg2,arg3) {
               return arg1 & " " & arg2 & " " & arg3;
         }
   }
}

Allows for smoother requiring of the module as a function versus a redundant component.

var say = require("say_something");

say("this","is","simpler"); 
@russplaysguitar
Copy link
Member

I think most well-written CFCs return this; from init() anyways?

@jfrux
Copy link
Contributor Author

jfrux commented Sep 29, 2012

I understand that, but I'm trying to make it easier to write smaller modules.

If your module is called the same thing as a single function then that's silly to type things such as
mkdirp.mkdirp. and it's silly to have an instance when all it is is a utility. Therefor, my proposal is to use a closure response. It allows us to stick to CFCs but make things more elegant on usage.

Most of the core will be larger modules but for tiny things it might make sense to just return something other than this.

For instance, several components in the new FPM utility will return an emitter.

Trying to think outside the box now that CF supports more and could grow into a very mature little language.

@russplaysguitar
Copy link
Member

I like it! Makes more sense now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants