|
List Info
Thread: New INPUT short-hand functions?
|
|
| New INPUT short-hand functions? |

|
2007-12-17 12:30:26 |
I recently found myself doing this a lot:
var a = INPUT({type:"textbox"});
var b = INPUT({type:"checkbox"});
var c = INPUT({type:"hidden"});
etc.
So I wanted to make short-hand functions like CHECKBOX and
HIDDEN
which would work exactly like INPUT, only with a
pre-specified type.
At first I thought I could do this:
CHECKBOX = createDOMFunc("input",
{type:"checkbox"});
but that eliminated all other attributes (since the
{type:"checkbox"}
replaced my attributes argument). I played around a bit,
and
eventually found that I could make it work with:
function CHECKBOX(){
arguments[0]["type"] =
"checkbox";
return INPUT.apply(this, arguments);
}
But that doesn't seem very MochiKit-ish to me, so I was
wondering if
there was a cleaner way to do the above using bind or
partial or
something. Also, I was curious as to how people feel about
these
short-hand functions, and whether or not they'd be useful
enough to
include in MochiKit.DOM.
Any thoughts/feedback would be appreciated.
Jeremy
So my question is, is th
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "MochiKit" group.
To post to this group, send email to mochikit googlegroups.com
To unsubscribe from this group, send email to
mochikit-unsubscribe googlegroups.com
For more options, visit this group at http://
groups.google.com/group/mochikit?hl=en
-~----------~----~----~----~------~----~------~--~---
|
|
| Re: New INPUT short-hand functions? |

|
2007-12-17 13:00:46 |
Maybe use MochiKit.Base.merge or MochiKit.Base.update:
function CHECKBOX() {
return INPUT.apply(this, update(arguments, {'type':
"checkbox"}));
}
- Kevin
On Dec 17, 2007 1:30 PM, machineghost <machineghost gmail.com> wrote:
>
> I recently found myself doing this a lot:
> var a = INPUT({type:"textbox"});
> var b = INPUT({type:"checkbox"});
> var c = INPUT({type:"hidden"});
> etc.
>
> So I wanted to make short-hand functions like CHECKBOX
and HIDDEN
> which would work exactly like INPUT, only with a
pre-specified type.
> At first I thought I could do this:
> CHECKBOX = createDOMFunc("input",
{type:"checkbox"});
>
> but that eliminated all other attributes (since the
{type:"checkbox"}
> replaced my attributes argument). I played around a
bit, and
> eventually found that I could make it work with:
> function CHECKBOX(){
> arguments[0]["type"] =
"checkbox";
> return INPUT.apply(this, arguments);
> }
>
> But that doesn't seem very MochiKit-ish to me, so I was
wondering if
> there was a cleaner way to do the above using bind or
partial or
> something. Also, I was curious as to how people feel
about these
> short-hand functions, and whether or not they'd be
useful enough to
> include in MochiKit.DOM.
>
> Any thoughts/feedback would be appreciated.
> Jeremy
>
>
>
> So my question is, is th
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "MochiKit" group.
To post to this group, send email to mochikit googlegroups.com
To unsubscribe from this group, send email to
mochikit-unsubscribe googlegroups.com
For more options, visit this group at http://
groups.google.com/group/mochikit?hl=en
-~----------~----~----~----~------~----~------~--~---
|
|
| Re: New INPUT short-hand functions? |

|
2007-12-17 13:02:24 |
Oops, that should probably be arguments[0]
On Dec 17, 2007 2:00 PM, Kevin Damm <kbdamm gmail.com> wrote:
> Maybe use MochiKit.Base.merge or MochiKit.Base.update:
>
> function CHECKBOX() {
> return INPUT.apply(this, update(arguments, {'type':
"checkbox"}));
> }
>
> - Kevin
>
>
> On Dec 17, 2007 1:30 PM, machineghost
<machineghost gmail.com> wrote:
> >
>
> > I recently found myself doing this a lot:
> > var a = INPUT({type:"textbox"});
> > var b = INPUT({type:"checkbox"});
> > var c = INPUT({type:"hidden"});
> > etc.
> >
> > So I wanted to make short-hand functions like
CHECKBOX and HIDDEN
> > which would work exactly like INPUT, only with a
pre-specified type.
> > At first I thought I could do this:
> > CHECKBOX = createDOMFunc("input",
{type:"checkbox"});
> >
> > but that eliminated all other attributes (since
the {type:"checkbox"}
> > replaced my attributes argument). I played around
a bit, and
> > eventually found that I could make it work with:
> > function CHECKBOX(){
> > arguments[0]["type"] =
"checkbox";
> > return INPUT.apply(this, arguments);
> > }
> >
> > But that doesn't seem very MochiKit-ish to me, so
I was wondering if
> > there was a cleaner way to do the above using bind
or partial or
> > something. Also, I was curious as to how people
feel about these
> > short-hand functions, and whether or not they'd be
useful enough to
> > include in MochiKit.DOM.
> >
> > Any thoughts/feedback would be appreciated.
> > Jeremy
> >
> >
> >
> > So my question is, is th
> > > >
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "MochiKit" group.
To post to this group, send email to mochikit googlegroups.com
To unsubscribe from this group, send email to
mochikit-unsubscribe googlegroups.com
For more options, visit this group at http://
groups.google.com/group/mochikit?hl=en
-~----------~----~----~----~------~----~------~--~---
|
|
| Re: New INPUT short-hand functions? |

|
2007-12-17 13:11:41 |
It still wouldn't work because you need the arguments
object, not
arguments[0], for the call to apply.
My personal preference would be to use merge because it
wouldn't
mutate the input object you give it, but there are
potential
efficiency concerns with all that extra overhead. The
original
solution was probably fine. MochiKit isn't a replacement
for
JavaScript, you shouldn't try and wedge it in everywhere
just because
it might be possible
-bob
On 12/17/07, Kevin Damm <kbdamm gmail.com> wrote:
>
> Oops, that should probably be arguments[0]
>
>
> On Dec 17, 2007 2:00 PM, Kevin Damm <kbdamm gmail.com> wrote:
> > Maybe use MochiKit.Base.merge or
MochiKit.Base.update:
> >
> > function CHECKBOX() {
> > return INPUT.apply(this, update(arguments,
{'type': "checkbox"}));
> > }
> >
> > - Kevin
> >
> >
> > On Dec 17, 2007 1:30 PM, machineghost
<machineghost gmail.com> wrote:
> > >
> >
> > > I recently found myself doing this a lot:
> > > var a =
INPUT({type:"textbox"});
> > > var b =
INPUT({type:"checkbox"});
> > > var c =
INPUT({type:"hidden"});
> > > etc.
> > >
> > > So I wanted to make short-hand functions like
CHECKBOX and HIDDEN
> > > which would work exactly like INPUT, only
with a pre-specified type.
> > > At first I thought I could do this:
> > > CHECKBOX =
createDOMFunc("input",
{type:"checkbox"});
> > >
> > > but that eliminated all other attributes
(since the {type:"checkbox"}
> > > replaced my attributes argument). I played
around a bit, and
> > > eventually found that I could make it work
with:
> > > function CHECKBOX(){
> > > arguments[0]["type"] =
"checkbox";
> > > return INPUT.apply(this, arguments);
> > > }
> > >
> > > But that doesn't seem very MochiKit-ish to
me, so I was wondering if
> > > there was a cleaner way to do the above using
bind or partial or
> > > something. Also, I was curious as to how
people feel about these
> > > short-hand functions, and whether or not
they'd be useful enough to
> > > include in MochiKit.DOM.
> > >
> > > Any thoughts/feedback would be appreciated.
> > > Jeremy
> > >
> > >
> > >
> > > So my question is, is th
> > > > >
> > >
> >
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "MochiKit" group.
To post to this group, send email to mochikit googlegroups.com
To unsubscribe from this group, send email to
mochikit-unsubscribe googlegroups.com
For more options, visit this group at http://
groups.google.com/group/mochikit?hl=en
-~----------~----~----~----~------~----~------~--~---
|
|
| Re: New INPUT short-hand functions? |

|
2007-12-17 13:18:33 |
Good point, and yeah - I hadn't considered needing to pass
the other
arguments to apply().
You're probably right about the overhead in using merge or
update, and
I had thought about efficiency issues when writing that
response. I
thought it would look more like MochiKit, as machineghost
asked, but
sometimes you use a hammer so much everything begins to look
like
nails.
Thanks, Bob, for the great toolkit!
- Kevin
On Dec 17, 2007 2:11 PM, Bob Ippolito <bob redivi.com> wrote:
> It still wouldn't work because you need the arguments
object, not
> arguments[0], for the call to apply.
>
> My personal preference would be to use merge because it
wouldn't
> mutate the input object you give it, but there are
potential
> efficiency concerns with all that extra overhead. The
original
> solution was probably fine. MochiKit isn't a
replacement for
> JavaScript, you shouldn't try and wedge it in
everywhere just because
> it might be possible
>
> -bob
>
>
> On 12/17/07, Kevin Damm <kbdamm gmail.com> wrote:
> >
> > Oops, that should probably be arguments[0]
> >
> >
> > On Dec 17, 2007 2:00 PM, Kevin Damm <kbdamm gmail.com> wrote:
> > > Maybe use MochiKit.Base.merge or
MochiKit.Base.update:
> > >
> > > function CHECKBOX() {
> > > return INPUT.apply(this, update(arguments,
{'type': "checkbox"}));
> > > }
> > >
> > > - Kevin
> > >
> > >
> > > On Dec 17, 2007 1:30 PM, machineghost
<machineghost gmail.com> wrote:
> > > >
> > >
> > > > I recently found myself doing this a
lot:
> > > > var a =
INPUT({type:"textbox"});
> > > > var b =
INPUT({type:"checkbox"});
> > > > var c =
INPUT({type:"hidden"});
> > > > etc.
> > > >
> > > > So I wanted to make short-hand functions
like CHECKBOX and HIDDEN
> > > > which would work exactly like INPUT,
only with a pre-specified type.
> > > > At first I thought I could do this:
> > > > CHECKBOX =
createDOMFunc("input",
{type:"checkbox"});
> > > >
> > > > but that eliminated all other attributes
(since the {type:"checkbox"}
> > > > replaced my attributes argument). I
played around a bit, and
> > > > eventually found that I could make it
work with:
> > > > function CHECKBOX(){
> > > > arguments[0]["type"] =
"checkbox";
> > > > return INPUT.apply(this,
arguments);
> > > > }
> > > >
> > > > But that doesn't seem very MochiKit-ish
to me, so I was wondering if
> > > > there was a cleaner way to do the above
using bind or partial or
> > > > something. Also, I was curious as to
how people feel about these
> > > > short-hand functions, and whether or not
they'd be useful enough to
> > > > include in MochiKit.DOM.
> > > >
> > > > Any thoughts/feedback would be
appreciated.
> > > > Jeremy
> > > >
> > > >
> > > >
> > > > So my question is, is th
> > > > > >
> > > >
> > >
> >
> > > >
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "MochiKit" group.
To post to this group, send email to mochikit googlegroups.com
To unsubscribe from this group, send email to
mochikit-unsubscribe googlegroups.com
For more options, visit this group at http://
groups.google.com/group/mochikit?hl=en
-~----------~----~----~----~------~----~------~--~---
|
|
| Re: New INPUT short-hand functions? |
  Denmark |
2007-12-18 06:29:55 |
Hi all,
Just wanted to add, that this function here:
function CHECKBOX(){
arguments[0]["type"] = "checkbox";
return INPUT.apply(this, arguments);
}
Does not work if you just call it like CHECKBOX() or with
any other
non-object first argument.
It should probably be:
function CHECKBOX(){
arguments[0] =
MochiKit.Base.update(arguments[0],{type:"checkbox"
});
return INPUT.apply(this, arguments);
}
As some has suggested already. Or simply ensure an object:
function CHECKBOX(){
if (typeof arguments[0] != "object")
arguments[0] = {};
arguments[0]["type"] = "checkbox";
return INPUT.apply(this, arguments);
}
And actually this is not correct still, as createDOM has
this note:
For convenience, if attrs is a string, null is used and
the string will
be considered the first node.
Thus you need to check if arg 0 is string, and if so,
prepend an empty
object:
function CHECKBOX(){
var args = MochiKit.Base.extend(arguments);
if (typeof arguments[0] == "string")
args.shift({});
elseif (typeof arguments[0] != "object")
args[0] = {};
args[0]["type"] = "checkbox";
return INPUT.apply(this, args);
}
I know, that INPUT's cannot have a text child, but not still
supporting
this "convenience" feature would still be
considered bad in my opinion.
The naming of these shorthand-functions however is not very
nice. They
should be named in lowercase, but just be kept on some
common object for
easy access and to avoid conflicts. The CAPS thing is
really... not nice.
--
Morten Barklund - Head of Development - TBWAPLAY
Kevin Damm wrote:
> Good point, and yeah - I hadn't considered needing to
pass the other
> arguments to apply().
>
> You're probably right about the overhead in using merge
or update, and
> I had thought about efficiency issues when writing that
response. I
> thought it would look more like MochiKit, as
machineghost asked, but
> sometimes you use a hammer so much everything begins to
look like
> nails.
>
> Thanks, Bob, for the great toolkit!
>
> - Kevin
>
>
> On Dec 17, 2007 2:11 PM, Bob Ippolito <bob redivi.com> wrote:
>> It still wouldn't work because you need the
arguments object, not
>> arguments[0], for the call to apply.
>>
>> My personal preference would be to use merge
because it wouldn't
>> mutate the input object you give it, but there are
potential
>> efficiency concerns with all that extra overhead.
The original
>> solution was probably fine. MochiKit isn't a
replacement for
>> JavaScript, you shouldn't try and wedge it in
everywhere just because
>> it might be possible
>>
>> -bob
>>
>>
>> On 12/17/07, Kevin Damm <kbdamm gmail.com> wrote:
>>> Oops, that should probably be arguments[0]
>>>
>>>
>>> On Dec 17, 2007 2:00 PM, Kevin Damm
<kbdamm gmail.com> wrote:
>>>> Maybe use MochiKit.Base.merge or
MochiKit.Base.update:
>>>>
>>>> function CHECKBOX() {
>>>> return INPUT.apply(this, update(arguments,
{'type': "checkbox"}));
>>>> }
>>>>
>>>> - Kevin
>>>>
>>>>
>>>> On Dec 17, 2007 1:30 PM, machineghost
<machineghost gmail.com> wrote:
>>>>> I recently found myself doing this a
lot:
>>>>> var a =
INPUT({type:"textbox"});
>>>>> var b =
INPUT({type:"checkbox"});
>>>>> var c =
INPUT({type:"hidden"});
>>>>> etc.
>>>>>
>>>>> So I wanted to make short-hand
functions like CHECKBOX and HIDDEN
>>>>> which would work exactly like INPUT,
only with a pre-specified type.
>>>>> At first I thought I could do this:
>>>>> CHECKBOX =
createDOMFunc("input",
{type:"checkbox"});
>>>>>
>>>>> but that eliminated all other
attributes (since the {type:"checkbox"}
>>>>> replaced my attributes argument). I
played around a bit, and
>>>>> eventually found that I could make it
work with:
>>>>> function CHECKBOX(){
>>>>> arguments[0]["type"]
= "checkbox";
>>>>> return INPUT.apply(this,
arguments);
>>>>> }
>>>>>
>>>>> But that doesn't seem very MochiKit-ish
to me, so I was wondering if
>>>>> there was a cleaner way to do the above
using bind or partial or
>>>>> something. Also, I was curious as to
how people feel about these
>>>>> short-hand functions, and whether or
not they'd be useful enough to
>>>>> include in MochiKit.DOM.
>>>>>
>>>>> Any thoughts/feedback would be
appreciated.
>>>>> Jeremy
>>>>>
>>>>>
>>>>>
>>>>> So my question is, is th
>
> >
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "MochiKit" group.
To post to this group, send email to mochikit googlegroups.com
To unsubscribe from this group, send email to
mochikit-unsubscribe googlegroups.com
For more options, visit this group at http://
groups.google.com/group/mochikit?hl=en
-~----------~----~----~----~------~----~------~--~---
|
|
| Re: New INPUT short-hand functions? |

|
2007-12-18 11:27:30 |
Thanks Kevin and Bob (I totally forgot about merge), but I
agree that
trying to use Mochikit to further simplify this pretty
simple function
is a bit overkill.
Also thanks Morten; I totally forgot to account for the
cases you
mentioned. However, I disagree with you on the case-naming
of
Mochikit's tag functions; personally, I love being able to
write code
like:
TABLE({},
TR({},
TD({} ...
and it wouldn't be as clean if instead I had to write:
MochiKit.elements.table({},
MochiKit.elements.tr({},
MochiKit.elements.td({} ...
or even:
elements.table({},
elements.tr({},
elements.td({} ...
Besides, if you want that kind of syntax, you can always
just do:
var elements = {table:TABLE, tr:TR, td:TD, ... etc.};
If I can find the time I'll submit a patch with these new
INPUT sub-
type functions sometime this week, in case anyone else wants
them.
I'm thinking I'll stick with standard naming convention for
createDOM
functions (CHECKBOX, HIDDEN, etc.) except for buttons, which
I'll do
as INPUTBUTTON to distinguish it from the BUTTON element.
Jeremy
On Dec 18, 4:29 am, Morten Barklund <mor... barklund.dk> wrote:
> Hi all,
>
> Just wanted to add, that this function here:
>
> function CHECKBOX(){
> arguments[0]["type"] =
"checkbox";
> return INPUT.apply(this, arguments);
>
> }
>
> Does not work if you just call it like CHECKBOX() or
with any other
> non-object first argument.
>
> It should probably be:
>
> function CHECKBOX(){
> arguments[0] =
MochiKit.Base.update(arguments[0],{type:"checkbox"
});
> return INPUT.apply(this, arguments);
>
> }
>
> As some has suggested already. Or simply ensure an
object:
>
> function CHECKBOX(){
> if (typeof arguments[0] != "object")
arguments[0] = {};
> arguments[0]["type"] =
"checkbox";
> return INPUT.apply(this, arguments);
>
> }
>
> And actually this is not correct still, as createDOM
has this note:
>
> For convenience, if attrs is a string, null is used
and the string will
> be considered the first node.
>
> Thus you need to check if arg 0 is string, and if so,
prepend an empty
> object:
>
> function CHECKBOX(){
> var args = MochiKit.Base.extend(arguments);
> if (typeof arguments[0] == "string")
args.shift({});
> elseif (typeof arguments[0] != "object")
args[0] = {};
> args[0]["type"] = "checkbox";
> return INPUT.apply(this, args);
>
> }
>
> I know, that INPUT's cannot have a text child, but not
still supporting
> this "convenience" feature would still be
considered bad in my opinion.
>
> The naming of these shorthand-functions however is not
very nice. They
> should be named in lowercase, but just be kept on some
common object for
> easy access and to avoid conflicts. The CAPS thing is
really... not nice.
>
> --
> Morten Barklund - Head of Development - TBWAPLAY
>
> Kevin Damm wrote:
> > Good point, and yeah - I hadn't considered needing
to pass the other
> > arguments to apply().
>
> > You're probably right about the overhead in using
merge or update, and
> > I had thought about efficiency issues when writing
that response. I
> > thought it would look more like MochiKit, as
machineghost asked, but
> > sometimes you use a hammer so much everything
begins to look like
> > nails.
>
> > Thanks, Bob, for the great toolkit!
>
> > - Kevin
>
> > On Dec 17, 2007 2:11 PM, Bob Ippolito <b... redivi.com> wrote:
> >> It still wouldn't work because you need the
arguments object, not
> >> arguments[0], for the call to apply.
>
> >> My personal preference would be to use merge
because it wouldn't
> >> mutate the input object you give it, but there
are potential
> >> efficiency concerns with all that extra
overhead. The original
> >> solution was probably fine. MochiKit isn't a
replacement for
> >> JavaScript, you shouldn't try and wedge it in
everywhere just because
> >> it might be possible
>
> >> -bob
>
> >> On 12/17/07, Kevin Damm <kbd... gmail.com> wrote:
> >>> Oops, that should probably be
arguments[0]
>
> >>> On Dec 17, 2007 2:00 PM, Kevin Damm
<kbd... gmail.com> wrote:
> >>>> Maybe use MochiKit.Base.merge or
MochiKit.Base.update:
>
> >>>> function CHECKBOX() {
> >>>> return INPUT.apply(this,
update(arguments, {'type': "checkbox"}));
> >>>> }
>
> >>>> - Kevin
>
> >>>> On Dec 17, 2007 1:30 PM, machineghost
<machinegh... gmail.com> wrote:
> >>>>> I recently found myself doing this
a lot:
> >>>>> var a =
INPUT({type:"textbox"});
> >>>>> var b =
INPUT({type:"checkbox"});
> >>>>> var c =
INPUT({type:"hidden"});
> >>>>> etc.
>
> >>>>> So I wanted to make short-hand
functions like CHECKBOX and HIDDEN
> >>>>> which would work exactly like
INPUT, only with a pre-specified type.
> >>>>> At first I thought I could do
this:
> >>>>> CHECKBOX =
createDOMFunc("input",
{type:"checkbox"});
>
> >>>>> but that eliminated all other
attributes (since the {type:"checkbox"}
> >>>>> replaced my attributes argument).
I played around a bit, and
> >>>>> eventually found that I could make
it work with:
> >>>>> function CHECKBOX(){
> >>>>>
arguments[0]["type"] = "checkbox";
> >>>>> return INPUT.apply(this,
arguments);
> >>>>> }
>
> >>>>> But that doesn't seem very
MochiKit-ish to me, so I was wondering if
> >>>>> there was a cleaner way to do the
above using bind or partial or
> >>>>> something. Also, I was curious as
to how people feel about these
> >>>>> short-hand functions, and whether
or not they'd be useful enough to
> >>>>> include in MochiKit.DOM.
>
> >>>>> Any thoughts/feedback would be
appreciated.
> >>>>> Jeremy
>
> >>>>> So my question is, is th
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "MochiKit" group.
To post to this group, send email to mochikit googlegroups.com
To unsubscribe from this group, send email to
mochikit-unsubscribe googlegroups.com
For more options, visit this group at http://
groups.google.com/group/mochikit?hl=en
-~----------~----~----~----~------~----~------~--~---
|
|
[1-7]
|
|