Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #17918
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!us.feeder.erje.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | JJ <jaejunks@nah.meh> |
| Newsgroups | comp.lang.javascript |
| Subject | Source code "objectifying" technique? |
| Date | Thu, 3 Jan 2013 10:34:35 +0000 (UTC) |
| Organization | A noiseless patient Spider |
| Lines | 49 |
| Message-ID | <XnsA13DB38A51C6jj@0.0.0.55> (permalink) |
| Injection-Date | Thu, 3 Jan 2013 10:34:35 +0000 (UTC) |
| Injection-Info | mx04.eternal-september.org; posting-host="904c555971ca2171d99874e113a9e21d"; logging-data="12957"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+i9foF70BptSYQRgbVlULfQMnPLKh2dGI=" |
| User-Agent | Xnews/5.04.25 |
| X-Face | \*\`0(1j~VfYC>ebz[&O.]=,Nm\oRM{of,liRO#7Eqi4|!]!(Gs=Akgh{J)605>C9Air?pad{sSZ09u+A7f<^paR"/NH_#<mE1S"hde\c6PZLUB[t/s5-+Iu5DSc?P0+4%,Hl |
| Cancel-Lock | sha1:eU+ldcEdPFI69Uy6Zl9P48ljNtc= |
| Xref | csiph.com comp.lang.javascript:17918 |
Show key headers only | View raw
Sometimes I need some a library from the web, but its functions are all
globally defined instead of object based. For example:
var config=123;
function abc(){
//does something
}
function def(){
//does something else
}
function ghi(a){
a=a||config;
abc(def(a));
}
function jkl(a){
a=a||config;
def(a);
}
I want to put all those functions in a self contained object so that
accessing them would be like:
theLib.abc();
theLib.ghi();
theLib.abc();
theLib.abc(456);
Usually I would convert each functions including all of the references
like below.
theLib={};
theLib.config=123;
theLib.abc=function(){
return theLib.config;
}
theLib.def=function(){
return theLib.config*10;
}
theLib.ghi=function(a){
a=a||theLib.config;
theLib.abc(theLib.def(a));
}
theLib.jkl=function(a){
a=a||theLib.config;
theLib.def(a);
}
As you can see, this is a tedious work. Even for a 2KB code. Is there a
simpler way to do this?
Back to comp.lang.javascript | Previous | Next — Next in thread | Find similar | Unroll thread
Source code "objectifying" technique? JJ <jaejunks@nah.meh> - 2013-01-03 10:34 +0000
Re: Source code "objectifying" technique? Stefan Weiss <krewecherl@gmail.com> - 2013-01-03 19:32 +0100
Re: Source code "objectifying" technique? JJ <jaejunks@nah.meh> - 2013-01-03 20:13 +0000
Re: Source code "objectifying" technique? Stefan Weiss <krewecherl@gmail.com> - 2013-01-03 23:57 +0100
Re: Source code "objectifying" technique? Stefan Weiss <krewecherl@gmail.com> - 2013-01-04 00:44 +0100
Re: Source code "objectifying" technique? JJ <jaejunks@nah.meh> - 2013-01-04 02:00 +0000
Re: Source code "objectifying" technique? Scott Sauyet <scott.sauyet@gmail.com> - 2013-01-03 10:37 -0800
Re: Source code "objectifying" technique? Scott Sauyet <scott.sauyet@gmail.com> - 2013-01-03 10:43 -0800
Re: Source code "objectifying" technique? JJ <jaejunks@nah.meh> - 2013-01-03 20:33 +0000
Re: Source code "objectifying" technique? Scott Sauyet <scott.sauyet@gmail.com> - 2013-01-03 13:09 -0800
Re: Source code "objectifying" technique? JJ <jaejunks@nah.meh> - 2013-01-04 02:33 +0000
csiph-web