简体   繁体   中英

Use start? method from opal-browser

I am trying to translate this js code into ruby code

document.ontouchstart ? 'touchstart' : 'click';

I am using opal-browser to get browser functionality. My current attempt is this:

touch = Browser::Event::Touch.new puts touch.start?

However this returns the error: Uncaught TypeError: Cannot read property 'type' of undefined

When I checked the error trace the error seems to be coming from a missing name property in the Touch class.

Hoping Opal community can help me out here

If you want to check if touch is supported you need to call Event::Touch.supported? .

For the error, it's happening because .new expects the event object as parameter, if you want to create a new event object you need to call .construct .

In retrospect it would have probably been better to have .construct be .new , and .new be .wrap or something on that line.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM