Wrap text
original (broken) code
|
|
var ReadHash = Class.create();
ReadHash.prototyte = {
initialize: function(data){
this.data=data;
},
read: function(){
this.data.each(function(pair) {
alert(pair.key + ' = "' + pair.value + '"');
});
}
};
var ReadMyData = Class.create();
ReadMyData.prototype = Object.extend(new ReadHash(),{
initialize: function(data){
this.data=data;
}
});
var TestReadHash = new ReadMyData($H({ var1: 'foo1', var2: 'foo2' }));
TestReadHash.read();
|
rewritten for Prototype 1.6 and later
|
|
var ReadHash = Class.create({
initialize: function(data){
this.data = data;
},
read: function(){
this.data.each(function(pair) {
alert(pair.key + ' = "' + pair.value + '"');
});
}
});
var ReadMyData = Class.create(ReadHash, {
initialize: function(data){
this.data=data;
}
});
var TestReadHash = new ReadMyData($H({ var1: 'foo1', var2: 'foo2' }));
TestReadHash.read();
|
... still, this is how the pros to it
|
|
var hash = $H({ foo:1, bar:2 })
alert(hash.inspect())
|