警报功能在coffeescript中不起作用

编程入门 行业动态 更新时间:2024-10-24 18:26:56
本文介绍了警报功能在coffeescript中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在博客中发现了CoffeeScript,并决定尝试一下,我的第一个项目/代码是

I found about CoffeeScript in a blog and decided to give it a try ,my first project/code with it was this

alert "Hello CoffeeScript!"

它不起作用并给出此回复

It doesn't work and gives this reply

ReferenceError: alert is not defined

有什么东西吗?我做错了吗?

is there anything i am doing wrong?

推荐答案

JavaScript是一种与环境概念紧密相关的语言。 浏览器和 Node.js 是两种运行JS代码的环境(CoffeeScript编译为JavaScript)。

JavaScript is a language which is strongly tied to the concept of environments. A browser and Node.js are two possible environments to run JS code (CoffeeScript compiles to JavaScript).

当JavaScript嵌入浏览器中时,全局对象为 window 。但是在Node.js中,全局对象只是 global 。

When JavaScript is embedded in a browser, the global object is window. But in Node.js, the global object is simply global.

在两种环境中都可以使用某些方法,例如核心JavaScript方法...

Some methods are available in both environments, like core JavaScript methods...

  • String.prototype 方法
  • Array.prototype 方法
  • Object.prototype 方法
  • 等。
  • String.prototype methods
  • Array.prototype methods
  • Object.prototype methods
  • etc.

...以及特定的窗口方法,例如 setInterval 或 setTimeout 。

... and specific window methods like setInterval or setTimeout.

但是, window.alert 显然在CLI中不可用。如果要在Node中使用此功能,则必须使用 alert-node ---> npm我警报节点。

However, window.alert is obviously not available in CLI. If you want this functionality in Node, you will have to use something like alert-node ---> npm i alert-node.

// alert.js var alert = require('alert-node'); alert('Hello');

命令: node alert.js

# alert.coffee alert = require 'alert-node' alert 'Hello'

命令: 咖啡alert.coffee

更多推荐

警报功能在coffeescript中不起作用

本文发布于:2023-11-27 15:56:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1638649.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:警报   中不   功能   coffeescript

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!