russplaysguitar / UnderscoreCF

An UnderscoreJS port for Coldfusion. Functional programming library.
http://russplaysguitar.github.com/UnderscoreCF/
MIT License
89 stars 38 forks source link

_.extend() not copying empty properties #7

Closed jfrux closed 11 years ago

jfrux commented 12 years ago

I'm trying to mixin a cfc's functions and "property" definitions, what is the best way to do this without initing?

For instance,

this = _.extend(this,new Paths());

I'd love to just be able to mixin the methods / property definitions of "Paths" instead of initing it and returning itself... There's gotta be a better way!

russplaysguitar commented 12 years ago

_.extend() simply loops over the publicly accessible members of an object/struct and copies them to the new object/struct.

Coldfusion's component extends="..." syntax allows you to define actual inheritance, which is what it sounds like you're looking for?

russplaysguitar commented 11 years ago

bump

jfrux commented 11 years ago

not necessarily looking for extends, looking to take the function definitions of one cfc and use them as mixin functions on another cfc.

extends only allows one cfc, but if we want to make two diff cfc's mixin to the existing cfc.

jfrux commented 11 years ago

similar to how you can include("mixin_functions.cfm") within a component and pull in a cfm of functions but without the need for the cfm file :)

maybe a new module for handling mixins...? :D

component name="core" {
        ...
        public any function includes(mixins...) {
               for (mixin in mixins) {
                     var mixinFuncs = getComponentMetaData(mixin);
                     for (func in mixinFuncs) {
                           this[func.name] = func;
                     }
               }
        }
        ...
}
component name="someBasicClass" extends="foundry.core"  {
      includes("./someMixinFuncs");
}
russplaysguitar commented 11 years ago

Hmm, can you provide an example of how you're trying to use _.extend() ?

russplaysguitar commented 11 years ago

i just reviewed this again, and i'm not sure that this sort of functionality makes sense for this project, given that it is intended to be a port of Underscore.js and there isn't anything in Underscore.js that does mixins for classes (yet)