var name = "The Window";   
  var object = {   
    name : "My Object",   
    getNameFunc : function(){   
        return this.name;   
    }   
};   
alert(object.getNameFunc());//My Object

---------------------------------------------------------------------------

var name = "The Window";   
  var object = {   
    name : "My Object",   
    getNameFunc : function(){   
        return function(){

return this.name;

}   
    }   
};   
alert(object.getNameFunc()());//The Window

---------------------------------------------------------------------------

var name = "The Window";   
  var object = {   
    name : "My Object",   
    getNameFunc : function(){   
        return name;   
    }   
};   
alert(object.getNameFunc());//The Window

变量和属性的区别:第一个return this.name 中 this指向的是object对象的name属性

第二个是一个闭包问题

第三个return name 指的是定义的name这个全局变量

随机推荐

  1. JPA 2.1 Coverter 注解

    @Converter(autoApply = true) public class VehicleConverter implements AttributeConverter<Vehicle, ...

  2. 2.Linux如何学习

    Linux的应用: 企业应用 个人应用 平行运算:所谓的平行运算指的是将原本的工作分成多份然后交给多台主机去运算,最终再将结果收集起来的一种方式.由于通过高速网络使用到多台主机(集群),将原本需要很长 ...

  3. Hyper-V 2012 R2 故障转移群集之建立域控(AD DS)与加入域

    Windows  2012 R2建立域控(AD DS)与加入域 Active Directory概述:          使用 Active Directory(R) 域服务 (AD DS) 服务器角 ...

  4. SpringMVC问题- MultipartConfig 配置问题以及解决方式

    http://www.cnblogs.com/weilu2/p/springmvc_fileupload_with_servlet_3_0.html

  5. Ionic- Android 开发环境搭建

    Ionic- Android 开发环境搭建 为时一周的IONIC ADNROID 环境终于在各种处理错误中搭建成功,以下记录下搭建过程中遇到的各种情况的处理办法. 一 首先,当然是enviroment ...

  6. tomcat 格式化输出到kafka

    cat /data/tomcat/conf/server.xml <Valve className="org.apache.catalina.valves.AccessLogValve ...

  7. [转]理解I/O Completion Port

    原文:http://dev.gameres.com/Program/Control/IOCP.htm 另附上:http://stackoverflow.com/questions/5283032/i- ...

  8. leetcode 406

    该算法题就是leetcode 406题, 题目描述: Suppose you have a random list of people standing in a queue. Each person ...

  9. Leetcode: Minimum Unique Word Abbreviation

    A string such as "word" contains the following abbreviations: ["word", "1or ...

  10. 【转】mybatis实战教程(mybatis in action),mybatis入门到精通

    MyBatis 目录(?)[-] mybatis实战教程mybatis in action之一开发环境搭建 mybatis实战教程mybatis in action之二以接口的方式编程 mybatis ...