# backtick_javascript: true module Browser module Delegate def [](property) method_missing(property) end def method_missing message, *args, &block if message.end_with? '=' message = message.chop property_name = property_for_message(message) arg = args[0] arg = arg.to_n if `arg && typeof arg.$to_n === 'function'` return `self[#{property_name}] = arg` else property_name = property_for_message(message) %x{ let value = self[#{property_name}]; let type = typeof(value); if (type === 'undefined') { return #{super}; } try { if (type === 'function') { #{args.map! { |arg| `arg && typeof arg.$to_n === 'function'` ? arg.to_n : arg }} value = value.apply(self, args); } if (value instanceof HTMLCollection || value instanceof NodeList) { let a = []; for(let i=0; i