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

October 2025

S M T W T F S
    1 23 4
5 678 9 1011
12 13 1415161718
19202122232425
262728293031 

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Oct. 16th, 2025 04:46 pm
Powered by Dreamwidth Studios