1、
document.getElementById('foo')
==>
$('foo')2、
var woot = document.getElementById('bar').valuevar
woot = $('bar').value
==>
var woot = $F('bar')3、
$('footer').style.height = '100px';
$('footer').style.background = '#ffc';
==>
$('footer').setStyle({ height: '100px', background: '#ffc'})4、
$('coolestWidgetEver').innerHTML = 'some nifty content'
==>
$('coolestWidgetEver').update('some nifty content')5、
new Ajax.Request('ninja.php?weapon1=foo&weapon2=bar')
==>
new Ajax.Request('ninja.php', { parameters: { weapon1: 'foo', weapon2: 'bar' }})6、
new Ajax.Request('blah.php', {
method: 'POST',
asynchronous: true,
contentType: 'application/x-www-form-urlencoded',
encoding: 'UTF-8',
})
==>
new Ajax.Request('blah.php')7、
Event.observe('myContainer', 'click', doSomeMagic)
==>
$('myContainer').observe('click', doSomeMagic)8、
$$('div.hidden').each(function(el){
el.show();
})
==>
$$('div.hidden').invoke('show')9、
$$('div.collapsed').each(function(el){
el.observe('click', expand);
})
==>
$$('div.collapsed').invoke('observe', 'click', expand)10、
$$('input.date').invoke('observe', 'focus', onFocus);
$$('input.date').invoke('observe', 'blur', onBlur);
==>
$$('input.date') .invoke('observe', 'focus', onFocus) .invoke('observe', 'blur', onBlur)11、
$('productTable').innerHTML =
$('productTable').innerHTML +
'<tr><td>' + productId + ' '
+ productName + '</td></tr><tr><td>'
+ productId + ' ' + productPrice +
'</td></tr>'
==>
var rowTemplate = new Template('<tr><td>#{id} #{name}</td></tr><tr><td>#{id} #{price}</td></tr>');$('productTable').insert( rowTemplate.evaluate({ id: productId, name: productName, price: productPrice })))12、
new Insertion.Bottom('blogEntry',
new Template('<div><h2>#{name}</h2><p>#{content}</p></div>')
.evaluate({
name: blogEntry.name,
content: blogEntry.content
}));
==>
$('blogEntry').insert(new Template('<div><h2>#{name}</h2><p>#{content}</p></div>') .evaluate({ name: blogEntry.name, content: blogEntry.content }), 'bottom' ); // "bottom" can be skippedFROM:
How well do you know prototypehttp://thinkweb2.com/projects/prototype-checklist/
How well do you know prototype (part II)http://thinkweb2.com/projects/prototype/?p=3