JavaScript注释与代码在同一行:是或否? [英] Javascript comments on same line as code: yes or no?

查看:114
本文介绍了JavaScript注释与代码在同一行:是或否?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我用Java编写的一些代码:

So here's some code I've written in Javascript:

var panRate = 120; //Max speed of the camera
var panAccelerate = 0.01; //Amount speed increases each frame
var panDecelerate = 1.05; //Amount speed is divided by each frame

是犹太洁食,将注释放在与代码? Firefox和Chrome似乎没有任何问题,但这是否有可能破坏某些浏览器?

Is that kosher, putting the comments on the same line as the code? Firefox and Chrome don't seem to be having any problems with it, but does that have the potential to break certain browsers?

推荐答案

Javascript有2种注释,并且都可以在所有浏览器中使用。

Javascript has 2 types of comments, and both work in all browsers.


  • //注释表示内联注释。 // 之后的该行上的所有字符均为注释。

  • / *注释* / 是阻止注释。带有 / * * / 的任何字符都是注释,并且可以跨越多行。

  • // comment denotes an "inline" comment. Any characters on that line after the // are a comment.
  • /* comment */ are "block" comments. Any characters withing the /* and */ are a comment, and can span multiple lines.

两者在所有javascript实现中都是通用的。

Both are valid in all javascript implementations, universally.

样式是这里唯一真正关心的问题。那是一个主观的问题。

Style is the only real concern here. And that is a far more subjective question.

这篇关于JavaScript注释与代码在同一行:是或否?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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