You can create chainability via a little object with chainable methods:
function classList(elt) {
var list = elt.classList;
return {
toggle: function(c) { list.toggle(c); return this; },
add: function(c) { list.add (c); return this; },
remove: function(c) { list.remove(c); return this; }
};
}
Then you can chain to your heart's content:
classList(elt).remove('foo').add('bar').toggle('baz')
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…