如何用node执行js代码
以前没怎么写过前端代码,一直以为,写前端代码需要在浏览器里面执行,打开控制台,然后debug之类的。
首先写一段js的代码
// 类
class Animal{
constructor(name) {
this.name = name
}
run() {
return `${this.name} is running`
}
}
const snake = new Animal('lily')
console.log(snake.run())
class Dog extends Animal{
bark(){
return `${this.name} is barking`
}
}
const xiaobao = new Dog('xiaobao')
console.log(xiaobao.run())
console.log(xiaobao.bark())
进入cmd窗口,执行命令node class.js
c>node class.js
lily is running
xiaobao is running
xiaobao is barking