我听说过Javascript insert&quot ;;"自动,这可能会导致问题 [英] I've heard Javascript inserts ";" automatically and that may cause problems

查看:116
本文介绍了我听说过Javascript insert&quot ;;"自动,这可能会导致问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我也听说Go也插入了它们,但它们跟着另一个方法

I've also heard that Go insert them too, but they followed a different approach

Javascript如何在解释时插入分号?

How does Javascript insert semicolons while interpreting?

推荐答案

我发现的最重要的事情之一是,假设你有一个函数可以返回坐标(或任何对象真的),类似于此。

One of the biggest things I've found is, let's say you have a function that returns coordinates (or any object really), similar to this.

function getCoordinates() {
    return
        {
            x: 10,
            y: 10
        };
}

你会期望找回一个对象吗?错误!你回来了未定义。解释器将代码转换为此

You would expect to get back an object right? WRONG! You get back undefined. The interpreter converts the code into this

function getCoordinates() {
    return;
        {
            x: 10,
            y: 10
        };
}

由于返回 by本身是一个有效的声明。你需要确保按以下方式写回报

Since return by itself is a valid statement. You need to be sure to write the return as follows

function getCoordinates() {
    return {
            x: 10,
            y: 10
        };
}

这篇关于我听说过Javascript insert&quot ;;"自动,这可能会导致问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆