在javascript中打印类中的变量

在javascript中打印类中的变量,javascript,Javascript,伙计们,我有简单的代码。。。但它打印出来还不确定,但我不知道为什么 函数myMove(){ 此值为0.pos; this.right=函数(){ 乐趣(); } 函数fun(){ 这个.pos++; } } var move=new myMove(); 警惕(move.right())您需要从fun()和this.right返回值 function myMove() { var pos = 0; this.right = function() { return fun()

伙计们,我有简单的代码。。。但它打印出来还不确定,但我不知道为什么

函数myMove(){
此值为0.pos;
this.right=函数(){
乐趣();
}
函数fun(){
这个.pos++;
}
}
var move=new myMove();

警惕(move.right())
您需要从
fun()
this.right
返回值

function myMove() {  
  var pos = 0;
  this.right = function() {
     return fun();
  }
  function fun(){
      return pos++;
  }

}

var move = new myMove();
alert(move.right());
试试这个

初始化时需要使用
pos
而不是
this.pos

函数myMove(){
pos=0;
this.right=函数(){
返回乐趣();
}
函数fun(){
这个.pos++;
返回此.pos;
}
}
var move=new myMove();
警惕(move.right())
函数myMove(){
pos=0;
this.right=函数(){
返回乐趣();
}
函数fun(){
返回++this.pos;
}
}
var move=new myMove();

警惕(move.right())
右侧
不返回任何内容。您希望它打印什么?@Carcigenicate希望它打印“1”
this.pos++
->
返回此。pos++
fun()->
返回乐趣()
你能解释为什么吗?顺便说一句,它不是“1”Oh-pos没有定义,因为pos和fun()上下文的
这个
不一样。检查我编辑的答案。