小编Cel*_*aro的帖子

pop() 不是函数 - nodejs

当我pop()在数组上调用函数时,NodeJS 出现一个奇怪的错误,它说TypeError: cars.pop is not a function......我很困惑。

有什么帮助吗?下面是代码。谢谢,

//callback chaining to avoid having multiple callbacks in the event queue
//only one callback calling others
function showCar(car, callback) {
  console.log('Saw a ' + car);
  if (car.length) {
    //register the function as asynchronous
    process.nextTick(function() {
      callback();
    })
  }
}

function logCars(cars) {
  var car = cars.pop();
  showCar(car, function() { //chaining of call backs
    logCars(car);
  });
}
var cars = ['ferrari', 'porsh', 'Hyundai', 'Peugeot'];
logCars(cars);
Run Code Online (Sandbox Code Playgroud)

javascript node.js

5
推荐指数
1
解决办法
9362
查看次数

错误:连接 ECONNREFUSED。未处理的“错误”事件 NodeJS

当我尝试发送 get 请求以加载静态文件时,我遇到了 Nodejs 错误 ECONNREFUSED 127.0.0.1:3000。我已经看到很多关于这个错误的问题,但显然没有直接回答为什么会抛出这个错误。下面是我的代码。我尝试将 localhost 更改为 127.0.0.1 或更改端口号 3000、7000、8080,但没有解决。有人可以建议吗?谢谢你。

//Basic web client retrieving content of file using get request

var http = require('http');

//options for request 

var options = {

hostname: 'localhost',
port: '3000',
path: '../html/hello.html'

};

//function to handle response from request

  function getResponse(response){

  var serverData='';

  response.on('data', function(chunk){

     serverData += chunk;
  });

   response.on('end', function(){

      console.log(serverData);
   });
 };

  http.request(options, function(response, error){

  getResponse(response);

}).end();
Run Code Online (Sandbox Code Playgroud)

node.js

2
推荐指数
1
解决办法
7091
查看次数

JavaScript 对象定义属性不起作用

所以我了解到在Javascript中我们可以使用defineProperties来定义对象的多个属性。因此,我在下面的简单代码中尝试了它,但我并没有安静地得到我想要的结果。访问器似乎不起作用,我不知道为什么。

var book = {};
Object.defineProperties(book,{
 _year: {
    value: 2004 },
 edition: {
    value: 1},
 year: {
    get: function(){
    this._year;},
    set: function(value){
    if(value>2004){
     this._year = value;
     this.edition = this.edition + value - 2004;
 });
 this.year = 2016;
 alert(book.edition); //1 why??
Run Code Online (Sandbox Code Playgroud)

javascript javascript-objects

1
推荐指数
1
解决办法
4768
查看次数

Visual Studio代码上的Python 3

所以我一直在网上试图找到如何在visual studio代码上使用python 3编译我的python程序.但是,似乎他们没有太多关于如何做的信息.下面是我的task.json文件的样子.我在做什么吗?

{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "0.1.0",
"command": "Python",
"isShellCommand": true,
"args": ["${file}"],
"showOutput": "always"
}
Run Code Online (Sandbox Code Playgroud)

任何建议都会非常感谢你

python python-3.x visual-studio-code

1
推荐指数
1
解决办法
2253
查看次数