Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #31596
| Path | csiph.com!news.mixmin.net!weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail |
|---|---|
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
| Newsgroups | comp.lang.javascript |
| Subject | Re: How to re-write the following? |
| Date | Fri, 21 Oct 2016 17:51:30 +0100 |
| Organization | PointedEars Software (PES) |
| Lines | 70 |
| Message-ID | <4239102.31r3eYUQgx@PointedEars.de> (permalink) |
| References | <954e5297-c7f0-4aee-a838-a2c44e356b88@googlegroups.com> <fr9r2d5see84.fy6vbbjg5xxt$.dlg@40tude.net> |
| Reply-To | Thomas 'PointedEars' Lahn <cljs@PointedEars.de> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset="UTF-8" |
| Content-Transfer-Encoding | 8Bit |
| X-Trace | solani.org 1477068806 32082 eJwNybEBwDAIA7CXIGDTnkNJ/f8JyaRBCDqnkmBCkC/m39Xfnhp17KtcfIkGbk6gzGJLeBbtAC84ETE= (21 Oct 2016 16:53:26 GMT) |
| X-Complaints-To | abuse@news.solani.org |
| NNTP-Posting-Date | Fri, 21 Oct 2016 16:53:26 +0000 (UTC) |
| User-Agent | KNode/4.14.2 |
| Cancel-Lock | sha1:9RC1lWw/441A/pD76uNHRW9H1jU= |
| X-User-ID | eJwNyskBwDAIA7CViI0hGYcc7D9Cq7fEGHHSQ+FqtbH8HUXisVG14cTEVQ1c0FcnpSVrL+JPb4L25NzmTH433RQn |
| X-NNTP-Posting-Host | eJwFwYEBgDAIA7CX2EqLngMI/59gQuiow0U5l2sCYNkRGDhvMjVuoOPzvtgHm7J6o2JO1A//oBBj |
| Xref | csiph.com comp.lang.javascript:31596 |
Show key headers only | View raw
JJ wrote:
> On Thu, 20 Oct 2016 21:06:06 -0700 (PDT), justaguy wrote:
>> Current, I have a function, that is working perfectly.
>> It's like this:
>> myFN = function() { ... }
>>
>> I wonder if we can rewrite it into something like below
>> ( function() {}
>> ());
>>
>> Then, how would myFN fit into it?
>
> You can't if you need to refer the function more than once.
The question is sufficiently unclear¹ to allow for several interpretations
of it (and the OP is not available on my server). Perhaps what was really
being asked is how to create a private namespace in which the function is
defined, which is a common task. If so, then one way would be to change
var myFN = function () {
// …
};
into
var myFN = (function () {
"use strict";
/* private variables */
return function () {
// …
};
}());
while the function call remains the same. Or into the module pattern –
var my = (function () {
"use strict";
/* private variables */
return {
fn: function () {
// …
}
};
}());
– and then instead of
myFN();
write
my.fn();
Note that “this” in the function will then refer to the same object as “my”.
Also note how a function is defined and called differ in my code style so
that it becomes easier to tell them apart.
________
¹ see <http://catb.org/esr/faqs/smart-questions.html>
--
PointedEars
FAQ: <http://PointedEars.de/faq> | SVN: <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-matrix>
Please do not cc me. / Bitte keine Kopien per E-Mail.
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
How to re-write the following? justaguy <lichunshen84@gmail.com> - 2016-10-20 21:06 -0700
Re: How to re-write the following? JJ <jj4public@vfemail.net> - 2016-10-21 20:46 +0700
Re: How to re-write the following? justaguy <lichunshen84@gmail.com> - 2016-10-21 08:42 -0700
Re: How to re-write the following? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-10-21 17:51 +0100
Re: How to re-write the following? justaguy <lichunshen84@gmail.com> - 2016-10-21 15:11 -0700
csiph-web