473,228 Members | 1,800 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,228 software developers and data experts.

Point of defining an inline function and calling it at the samepoint?

Ok, I'm sure that subject is confusing, but I noticed the following
curious code on the main page of the "Vitamin" web developer's page
<http://www.thinkvitamin.com/>:

<script type="text/javascript">
//<![CDATA[
(function(id) {
document.write('<script type="text/javascript" src="' +
'http://www.northmay.com/deck/deck' + id + '_js.php?' +
(new Date().getTime()) + '"></' + 'script>');
})("VM");
//]]>
</script>

The key thing I noticed is that this is defining an inline function,
and calling it immediately. This is a very curious technique. I
could almost see doing this if you had several repeated strings you
wanted to substitute, but this example only uses the func parameter
once.

Otherwise, what is the point of doing it this way?
Jun 27 '08 #1
2 1354
VK
On Apr 12, 10:35 pm, "david.karr" <davidmichaelk...@gmail.comwrote:
Ok, I'm sure that subject is confusing, but I noticed the following
curious code on the main page of the "Vitamin" web developer's page
<http://www.thinkvitamin.com/>:

<script type="text/javascript">
//<![CDATA[
(function(id) {
document.write('<script type="text/javascript" src="' +
'http://www.northmay.com/deck/deck'+ id + '_js.php?' +
(new Date().getTime()) + '"></' + 'script>');
})("VM");
//]]>
</script>

The key thing I noticed is that this is defining an inline function,
and calling it immediately. This is a very curious technique. I
could almost see doing this if you had several repeated strings you
wanted to substitute, but this example only uses the func parameter
once.

Otherwise, what is the point of doing it this way?
In the particular case you have posted it is nothing but a "show up
case". The author either wanted to show someone how cool he is or -
most probably - he was feeling himself cooler by doing that. How
strange it might be, the latter reason always had a great impact on
coding practice trends - the "squeeze crypt" has the same roots btw.

Overall a function declaration wrapped into expression has some useful
applications. JScript and JavaScript are treating them a bit
differently, but for anonymous function such difference is not very
important.
Jun 27 '08 #2
"david.karr" <da**************@gmail.comwrites:
Ok, I'm sure that subject is confusing, but I noticed the following
curious code on the main page of the "Vitamin" web developer's page
<http://www.thinkvitamin.com/>:

<script type="text/javascript">
//<![CDATA[
CDATA? That suggests that this is an XHTML document ....
(function(id) {
document.write('<script type="text/javascript" src="' +
.... but document.write generally doesn't work for properly parsed
XHTML documents.
'http://www.northmay.com/deck/deck' + id + '_js.php?' +
(new Date().getTime()) + '"></' + 'script>');
And here the string is split into two after the "</", where it
should, according to the HTML specification, have been split
between those two, i.e., '"><' + '/script>'.
})("VM");
//]]>
</script>

The key thing I noticed is that this is defining an inline function,
and calling it immediately. This is a very curious technique. I
could almost see doing this if you had several repeated strings you
wanted to substitute, but this example only uses the func parameter
once.
That is the typical use. That, and creating local variables without
poluting the global namespace.

I don't believe there is any idea to this. It's probably just someone
who have inlined a function declaration, or code generated by a
server-side script that is prepared to be more general.
Otherwise, what is the point of doing it this way?
None, in this case.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jun 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Senthilraja | last post by:
I have the following program using templates. Someone please let me know the syntax to be used for defining the member functions push, pop etc. as non-inline functions. #include <iostream>...
14
by: Chris Mantoulidis | last post by:
I am not clear with the use of the keyword inline... I believe you add it do a function when you implement the function inside the header file where the class is stored... But is that all? What...
47
by: Richard Hayden | last post by:
Hi, I have the following code: /******************************** file1.c #include <iostream> extern void dummy(); inline int testfunc() {
43
by: Patrick Laurent | last post by:
Hello I have a program with many many inlined template functions It is essential for the execution speed that every (or almost every) function marked as inlined, becomes really inlined by the...
3
by: junky_fellow | last post by:
What is an inline function ? When should we declare a particular function as inline ? If a function is declared to be inline, does that mean that the entire code for that function is subtituted...
7
by: Wu Shaohua | last post by:
Hi Guys, 1. As we know usually we should not define a constructor as inline. I also learned if we define a member function inside the class this member function will be automatically be...
2
by: Amal P | last post by:
Hi, This is the program that i made to test the usage of inline function. I am using vc 6.0 compiler. Please see the below program. int NonInline( int a, int b ) { return ( a b )? a: b; }
14
by: jg | last post by:
Does C++ standard require an inline function be generated all the time ? For example, #include <iostream> using namespace std; inline int foo() {
9
by: lucifer | last post by:
Hi I have a little problem regarding inline functions ,does declaring a function inside the class definition make it inline or not.
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.