简体   繁体   English

功能默认值输入

[英]function default value input

i'm testing my website and everything is worked as wished, but when i work on ipad using safari i got this error: 我正在测试我的网站,一切都按照希望工作,但当我使用safari在ipad上工作时,我收到此错误:

Unexpected token '='. 意外的标记'='。 Expected a ')' or a ',' after a parameter declaration 在参数声明之后预期')'或','

This the line of my code where give me the error: 这是我的代码行给我的错误:

function searchLente(side = null) {

The problem is that when i test my website on a desktop is working (chrome, safari...) But not on ipad... 问题是,当我在桌面上测试我的网站工作(铬,野生动物园...)但不是在iPad上...

PD: My ipad is updated at last version. PD:我的ipad在最新版本更新。

Default values are a ES6 thingy, and most browsers don't support them. 默认值是ES6,大多数浏览器都不支持它们。

Change it to 将其更改为

function searchLente(side) {
    side = side === (void 0) ? null : side;

void 0 is a way to tell undefined . void 0是一种告诉undefined This code will check if size is undefined and then set size to a default value ( null ) if is true. 此代码将检查size是否undefined ,然后将size设置为默认值( null ),如果为true。

NOTE: This is what typescript actually does when transpiling to ES5 (which don't has defaults). 注意:这是在转换为ES5(没有默认值)时打字机实际执行的操作。

NOTE2: Don't think that your users will have ES6 enabled, as there are still browsers which don't support it. 注意2:不要认为您的用户将启用ES6,因为仍然有不支持它的浏览器。 Use Babel if you want to write ES6 code and make it work for most browsers, or simply don't write ES6 code. 如果您想编写ES6代码并使其适用于大多数浏览器,或者只是不编写ES6代码,请使用Babel

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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