<html>
<head>
<script language="javascript">
<!--
      function employee(name,code,designation){
  this.name=name
  this.code=code
  this.designation=designation

  }
     newemp=new  employee("John Dias","A001",'职员');
 document.write("雇员姓名:"+newemp.name+"<br>");
 document.write("雇员代号:"+newemp.code+"<br>");
 document.write("头衔:"+newemp.designation);
 </script>
 </head></html>this在这里是不是指代下面新建的newemp对象,还是什么意思,好多程序中的代码就是这样一知半解的(自学java)

解决方案 »

  1.   

    this 就在调用你这个方法的当前对象。
    这里就是newemp
      

  2.   

    newemp = new  employee("John Dias","A001",'职员'); this.name=name 
    this.code=code 
    this.designation=designation this是当前的对象 就是第一行代码
      

  3.   

    this指当前函数对象吧!
    employee的原始对象
    就像java类那样
    function employee(name, code, designation){
                 alert(this.name)//这里是undefined 说明这里是没有值的,
                    this.name = name//
    alert(this.name)//这里把John Dias赋予了this.name
                    this.code = code
                    this.designation = designation
                }
                
                newemp = new employee("John Dias", "A001", '职员');
                document.write("雇员姓名:" + newemp.name + " <br>");
                document.write("雇员代号:" + newemp.code + " <br>");
                document.write("头衔:" + newemp.designation);
      

  4.   

    就是产生你所定义的employee的对象的时候,这个对象本身。进而完成参数的赋值!
      

  5.   

    this指当前对象的引用
    this.name就是为了区分参数name与数据成员name的
      

  6.   

    this是在调用当前对象的方法或者成员
      

  7.   

    小菜回答:楼上的都是正解 this指当前对象的引用 
    我就说几个例子 :
    public class Student{
    private String name ;
    priavte  int age;
    public Student()
    public Student(String name ,int age)
    {
        this.name=name;// 当类的属性名和方法的局部变量名重名时用this来表示当前对象。哪么this.age 就表示当前对象的age属性。
        this.age=name;
    }
    }
      

  8.   

    接我上面的帖子 :刚才点错了写错个地方 无参的构造方法没写完。
    public   class   Student{ 
    private   String   name   ; 
    priavte     int   age; 
    public   Student(String name) 
    {
        this.Student(name,20);// 此处的this还可以调用本类中其他的构造方法。
    }
    public   Student(String   name   ,int   age) 

            this.name=name;//   当类的属性名和方法的局部变量名重名时用this来表示当前对象。哪么this.age   就表示当前对象的age属性。 
            this.age=name; 

      

  9.   

    这个就是调用你当前对象的属性,其实你也可以不用这样,上面的代码的实参中定义的跟你的类属性一样了,为了避免被隐藏,就用this调用当前对象的属性!!!
    function employee(String n,String c,String d){ 
      name=n; 
      code=c; 
      designation=d; 
    }
    这么写你应该会看的清楚点,但是这么写的话程序不是很清楚明了!!!建议用this调用!!!
    LZ你这个程序肯定通不过
    function employee(name,code,designation){ /*这个方法的参数怎么没有类型?应该好匹配类型,应该这么写
      this.name=name                             (String name,String code,String designation)
      this.code=code                          */
      this.designation=designation 
      } 
    看看这个,里面有关于关键字this的三大用法
    http://blog.csdn.net/aa278489710/archive/2008/11/14/3298014.aspx
      

  10.   

    this指调用当前方法的对象本身的引用,上面this指的就是newemp即employee对象的引用。