-4

Sorry if i am not clear enough as i am new to javascript.

let me explain with an example.

for example if i have

*

(function()
var foo;
windows.foo = foo = (function()){
function foo (a,b){
this.colour = a.colour
this.shape = b.shape
}
return foo;
})();
}).call(this);*

Now my questions was

  1. regarding the scope, when the "foo" is global and local.

2.how would I display the value of foo in the HTML. I cannot use document.getElementbyid(); is there any other functions that i can use?????

Gabf Hann
  • 350
  • 4
  • 16
  • It should be `getElementById`, not `getelementbyid`. – Afsa Sep 12 '14 at 14:39
  • `here the second asdf is a class and the fist asdf is a global variable.` wrong, on both points. `// why Parenthesis "()";` research IIFE. `// what does it mean and its significance?` depends on what `this` is and what it is executing (you left that out). Question two just doesn't make any sense. – Kevin B Sep 12 '14 at 14:39
  • read http://stackoverflow.com/questions/16937022/iife-invocation-in-javascript. Notice that the inner IIFE is totally pointless. – Bergi Sep 12 '14 at 14:43
  • PUT ON HOLD untill when....You stupidd dumbbb mother fcÄkers – Gabf Hann Sep 15 '14 at 09:59

1 Answers1

0

By

var asdf;

you declare a variable in the current scope.

window.asdf = ...

sets the value of the property "asdf" of the object named "window".

The

return asdf;

returns the function "asdf" just declared; this is assigned to your (local) variable "asdf" as well as to window.asdf. The parenthesis call the locally defined function (resulting in the before-mentioned return).

.call(obj);

invokes the function and sets the this-pointer inside the function to "obj".

fast
  • 885
  • 7
  • 15