summaryrefslogtreecommitdiffstats
path: root/samples/weird_function.js
blob: d02d1726337a59bb443e6d67bd7dd21c3d733e59 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/* seems like we can assign anonymous function to an IDENTIFIER, without var in
 * front of it. the fuck seriously
 *
 * this way I guess, we have hidden a function, that only identifier points to
 */

/* the fuck, why does 'var' does then if it's not needed ?
 * http://stackoverflow.com/questions/2485423/javascript-is-using-var-to-declare-variables-optional
 *
 * id with var has local scope, whereas id without var wasn't prev declared, it would
 * eventually be attached to global object, outermost scope, if it was declared, then
 * we would be just redefining its content, duh!
 */

p = 12;
console.log(p);

foo = function(txt) {
    this.id = 'foo';
    console.log('hello, ' + txt);
}

foo.call(foo, 'world');
console.log('id of foo is: ' + foo.id);

var bar = foo; /* this is just a reference */
bar.call(bar, 'world');
bar.id = 'bar';
console.log('id of bar is: ' + bar.id);
console.log('id of foo is: ' + foo.id);