Douglas Crockfords J-TBP book using jsfiddle で本当に素晴らしい deentityify の例を実行しようとしています
String.method('deentityify', function() {
// The entity table. It maps entity names to
// characters.
var entity = {
quot: '"',
lt: '<',
gt: '>'
};
// Return the deentityify method.
return function() {
// This is the deentityify method. It calls the string
// replace method, looking for substrings that start
// with '&' and end with ';'. If the characters in
// between are in the entity table, then replace the
// entity with the character from the table. It uses
// a regular expression (Chapter 7).
return this.replace(/&([^&;]+);/g, function(a, b) {
var r = entity[b];
return typeof r === 'string' ? r : a;
});
};
}());
document.writeln('<">'.deentityify()); // <">
- http://jsfiddle.net/cspeter8/7Pjzs/2/を参照してください- 動作しません! 結果ペインに '<">' が表示されるはずですが、何も表示されません。謎を解きたい人はいますか?