Jun. 14th, 2006

juan_gandhi: (Default)
I am sure you know Javascript. Or maybe you don't. Or maybe you want to play with it - then download Rhino from Mozilla - it is an interactive Javascript interpreter (to run it, do this: java -jar js.jar. Rhino's version of Javascript has print(message) and load(filename) functions, but does not have alert(message) - so below I will use print() insteead of the usual alert()

var obj = new Object()
obj.myname = "John Walker"

var my = "my"
var name = "name"
print(obj[my + name])


This code will duly print "John Walker".

How about this:Read more... )
var x = new Object()
x.a = 2
var y = new Object()
y.a = "The A of Y"

y.f = function(param) { 
  var self = this
  param.f = function(arg) { print(self.a + arg + this.a) }
}

y.f(x)
x.f(" is not ")


And the answer is... "The A of Y is not 2"

Profile

juan_gandhi: (Default)
Juan-Carlos Gandhi

September 2025

S M T W T F S
 1 2345 6
78 9 10 111213
14151617181920
21222324252627
282930    

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Sep. 13th, 2025 11:14 pm
Powered by Dreamwidth Studios