Subscribe
var select = document.createElement("select")
// ... add options, etc.
var meta = $(document.createElement("div"))
// ... add content, etc.
select.changeMeta = function()
{
meta.html($(this.options.item(this.options.selectedIndex)))
}
$(select).change(function()
{
var self = this
meta.fadeOut("fast",function()
{
self.changeMeta()
meta.fadeIn("fast")
}
})
var O = function( foo )
{
this.foo = foo
}
O.prototype.getFoo = function()
{
return this.foo
}
var myO = new O("bar")
alert(myO.getFoo()) // alerts "bar"
myO.foo = "quux"
alert(myO.getFoo()) // alerts "quux"
var O2 = function( foo )
{
this.getFoo = function() { return foo }
}
var myO = new O("bar")
alert(myO.getFoo()) // alerts "bar"
// myO doesn’t have a "foo" attribute, so it cannot be changed!
var x = 10
var x3 = Math.pow(x,3) // x3 = 10^3 = 1000
var raise = function( n )
{
return function( base ) { return Math.pow(base,n) }
}
var cube = raise(3)
var x = 10
var x3 = cube(x) // x3 = 10^3 = 1000
x = 0;
f = function() { return x; }
g = function() { x = 1; return f(); }
alert(g()) // alerts "1"
g changes the value of x, which is not in its local scope. The same value of x is seen by both f and g.You are not logged in, either login or create an account to post comments
posted by sanko at 4:26 PM on May 8, 2007