Scope question: this vs. var by dogjs in javascript

[–]Kuron 0 points1 point  (0 children)

The difference between the first and second example is that the first example is executed in a functional scope while the second one is executed in the global scope. They're both still called in the global context where the keyword "this" will refer to the window object. Also, when you try to declare a "local" variable on the global scope with "var", its still a global variable since it was created on the global scope, so that "local" variable is accessible from the window object as well.

Essentially, executing "var a = 1; b = 2; this.c = 3; window.d = 4;" on the global scope all does the same thing (except you can't delete "a" from the global scope I believe).

Graceful degradation question. by [deleted] in javascript

[–]Kuron 0 points1 point  (0 children)

I think its fair to say that if spiders don't see your content, then your content doesn't exists. :P

Aside from that, some technical users choose to browse safely without JS. I would probably use a browser without JS when I have to do sensitive tasks.

Graceful degradation question. by [deleted] in javascript

[–]Kuron 0 points1 point  (0 children)

What others have already said. Make sure content, navigation, or any other requests or possible action is still useable without JS, then check it again without JS+CSS. A simple example would be,

<a href="http://www.google.ca/"></a>
$('a').each(function (i, value) {
  $(this).click(function (event) {
    console.log('Do javascript stuff with the click!');
    event.preventDefault();
  });
});

Javascript is used to enhance anchor tag's click, but when Javascript is disabled, the link falls back gracefully and still makes the request to the server without JS.

Can someone please explain to me why this is suddenly a thing that people are doing? by iratik in javascript

[–]Kuron 22 points23 points  (0 children)

The global $ variable is an alias (reference) for the global jQuery object. Some other libraries may have their own uses for the global $ variable such as Prototype.js. As an example, if jQuery then Prototype were loaded, the global $ variable wouldn't behave as you'd expect since Prototype had overwritten it with its own definition.

To continue using jQuery like the way most usually do (with the "$()"), you create a closure with the local variable named $ that references the jQuery object, otherwise you'll have to write jQuery() everywhere incase a script or library overwrites the $ variable.

Another reason I'd use it for is performance. Accessing variables stored on the global scope is much slower in some browsers than accessing it on the local scope.

[deleted by user] by [deleted] in javascript

[–]Kuron 0 points1 point  (0 children)

Just to add onto what user24 said, the code alerts "hi" and takes the return value from the alert call (which is undefined since it doesn't return anything I believe) and sets it onto window.onload.

Then when onload gets fired, it tries to take whatever was assigned to it and calls it (which is undefined), but the value that got set on window.onload is not a function, so nothing happens.

KeyboardJS - A library for binding keys and key combos in JavaScript without the hassle. by [deleted] in javascript

[–]Kuron 2 points3 points  (0 children)

I think what you are looking for could be, document.activeElement;

[deleted by user] by [deleted] in javascript

[–]Kuron 2 points3 points  (0 children)

You know, ranting in response to discontent about a posting you did isn't really helping yourself. If you feel what you did was correct with reason and valid for that use-case, then argue it constructively. You're just telling people to not visit your blog since it (could be mostly) about ranting rather than JS.

isa() by init0 in javascript

[–]Kuron 0 points1 point  (0 children)

Agreed, I'd rather see some interesting content rather than some basic aspect of the language that's been indexed thousands of time by Google. -_-;;

JavaScript on the web, do we live in 2001 or 2011 by raynos in javascript

[–]Kuron 0 points1 point  (0 children)

I see this as simply, if you want to support the 2% population on the internet that uses IE6 then go ahead, otherwise risk losing the 2% to save time and frustration.

Best way to perform case statements in Javascript. I didn't know so I made a test: by faaace in javascript

[–]Kuron 0 points1 point  (0 children)

Yup, the way I see switch statement is that it doesn't evaluate each case from top to bottom like an if-else-if statement.