Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Update the what-is-this article.

  • Loading branch information...
commit 1810a57710f31ba45aa83bb5748329fefe244403 1 parent ad9a576
Tim Caswell authored
2  articles/what-is-this.markdown
View
@@ -1,7 +1,7 @@
Title: What is "this"?
Author: Tim Caswell
Date: Mon Mar 08 2010 12:59:10 GMT-0600 (CST)
-Node: v0.1.91
+Node: v0.1.102
Most people that learn JavaScript are coming from a background in another language. This brings with it a view of how the world works that may be different from how it really works in JavaScript. For this and other reasons, JavaScript is often misunderstood. It's not entirely our fault, the language was designed to work like one thing (scheme-like), but look like another (c-like). This article will describe lexical scope and the "`this`" variable and how to control them rather than be controlled by them when in coding JavaScript.
2  articles/what-is-this/closure.js
View
@@ -1,5 +1,3 @@
-var sys = require('sys');
-
// Make a function that returns a closure function.
function myModule() {
var name = "tim", age = 28;
10 articles/what-is-this/lexical.js
View
@@ -1,5 +1,3 @@
-var sys = require('sys');
-
var name = "outer";
function one() {
var name = "middle";
@@ -7,13 +5,13 @@ function one() {
function two() {
var name = "inner";
// Here `name` is "inner" and `other` is "findme"
- sys.p({name: name, other: other});
+ console.dir({name: name, other: other});
}
two();
// Here `name` is "middle" and `other` is "findme"
- sys.p({name: name, other: other});
+ console.dir({name: name, other: other});
}
one();
// Here `name` is "outer" and `other` is undefined.
-sys.p({name: name});
-sys.p({other: other});
+console.dir({name: name});
+console.dir({other: other});
4 articles/what-is-this/this.js
View
@@ -1,5 +1,3 @@
-var sys = require('sys');
-
//person
var Person = {
name: "Tim",
@@ -43,4 +41,4 @@ function makeOlder(years, newname) {
//use-it
makeOlder.call(Person, 2, "Old Tim");
makeOlder.apply(Dog, [1, "Shaggy"]);
-sys.p({Person: Person, Dog: Dog});
+console.dir({Person: Person, Dog: Dog});
6 articles/what-is-this/var.js
View
@@ -1,5 +1,3 @@
-var sys = require('sys');
-
//globals
global_var = true;
function someFunc() {
@@ -29,7 +27,7 @@ nested_sum(3); // Expected value is 10, but i values get tangled
//onevar
name = "Tim";
function greet() {
- sys.p(name);
+ console.dir(name);
// name is undefined
// Lots of code, and them later on you have:
var name;
@@ -37,7 +35,7 @@ function greet() {
greet();
function greet2(name) {
- sys.p(name);
+ console.dir(name);
// name is "Tim" because functions arguments are special.
// Lots of code, and them later on you have:
var name;
Please sign in to comment.
Something went wrong with that request. Please try again.