`
joshokn
  • 浏览: 102148 次
  • 性别: Icon_minigender_1
最近访客 更多访客>>
社区版块
存档分类
最新评论

'Function Object' in js

阅读更多
Here is a paper that introduce the 'Function Object' in javascript.

http://www.permadi.com/tutorial/jsFunc/index.html

我的一点理解:函数并不会和某个实体绑定,函数可以被任何地方使用,可以看成一个数值。并不像java中的类的方法一定是和类名绑定的。(这个思维转换确实有点费劲)

以代码实例述之:

1.
Engine.prototype.start = function(){
	var eventEngine = this;
	    window.setInterval(function(){eventEngine.GetEventsInfo();},5000);
	
}



2.
Engine.prototype.start = function(){
	var eventEngine = this;
	    window.setInterval(eventEngine.GetEventsInfo,5000);	
}


差别大了,2中的window.setInterval传得第一个参数只是函数,进入GetEventsInfo()函数体后,this并不指代eventEngine,而在第一个例子中,将这样一个
引用
eventEngine.GetEventsInfo()
操作作了封装,进入GetEventsInfo()函数体内,this就是指代eventEngine了。
3.
Engine.prototype.start = function(){
	var eventEngine = this;
	    window.setInterval('eventEngine.GetEventsInfo()',5000);	
}

这是第三种可以实现的做法,因为js会去寻找这样的字符串'eventEngine.GetEventsInfo()',待找到匹配字符串的函数就会调用相应的方法,
这个特性我想不起来叫什么了(也许里面就是做了个判断
window.setInterval(fucntion , time);
if(function=='Function()'){
    //...
}else{
    //find the String in Function stack;
    var result = search('function');
    if(result){
      //...      
    }
    else{
     //error!
    }
   
}


分享到:
评论

相关推荐

    javascript面向对象编程指南 2nd

    The basics of object-oriented programming, and how to apply it in the JavaScript environment How to set up and use your training environment (Firebug) In depth discussion of data types, operators, ...

    JavaScript Functional Programming for JavaScript Developers (PDF, EPUB, MOBI)

    Code using the powerful object-oriented feature in JavaScript Master DOM manipulation, cross-browser strategies, and ES6 Understand the basic concurrency constructs in Javascript and best performance ...

    Sortable前端框架

    Sortable is a <s>minimalist</s> JavaScript library for reorderable drag-and-drop lists. Demo: http://rubaxa.github.io/Sortable/ ## Features * Supports touch devices and [modern]...

    Professional JavaScript for Web Developers英文版

    fly graphicsJavaScript API changes in HTML5how browsers handle JavaScript errors and error handlingfeatures of JavaScript used to read and manipulate XML datathe JSON data format as an alternative to ...

    json3.js开发板和生产版本

    JSON.parse(jsonstr); 对JSON字符串反序列化成JSON对象;JSON.stringify(jsonobj); 将JSON对象序列化成JSON字符串,传到后台再进行反序列化, 官方地址 ...相对json.js与json2.js json3.js做了很多优化,建议使用

    JSON2.JS JSON.JS JSON_PARSE.JS

    json2.js: This file creates a JSON property in the global object, if there isn't already one, setting its value to an object containing a stringify method and a parse method. The parse method uses ...

    js.rar(react初学者简单测试用babel.js,react-development.js,react-dom.js)

    return t.m=e,t.c=r,t.p="",t(0)}(function(e){for(var t in e)if(Object.prototype.hasOwnProperty.call(e,t))switch(typeof e[t]){case"function":break;case"object":e[t]=function(t){var r=t.slice(1),n=e[t[0]...

    Professional JavaScript for Web Developers, 3rd Edition

    built-in reference types such as object and array object-oriented programing powerful aspects of function expressions Browser Object Model allowing interaction with the browser itself detecting the ...

    js如何打印object对象

    js调试中经常会碰到输出的内容是对象而无法打印的时候,光靠alert只能打印出object标示,却不能打印出来里面的内容,甚是不方便,于是各方面整理总结了如下一个函数,能够将数组或者对象这类的结果一一打印出来,...

    Javascript Object.extend

    既然是类,那么就有抽象... Object.extend = function(destination, source) { for (property in source) { destination[property] = source[property]; } return destination; } Object.prototype.extend = function(o

    Programming JavaScript Applications

    With this digital Early Release edition of Programming JavaScript Applications, you get the entire book bundle in its earliest form—the author's raw and unedited content—so you can take advantage of...

    javascript中Object使用详解

    function forEach(o){ var html =””; for(var i in o){ html += i+”=”+o[i]+” “; } console.log(html); console.log(o); } //1 //Object.create(proto) //Object.create(proto,descriptors) //使用指定的原型...

    JavaScript的Function详细

    Function (Built-in Object) Function (內置對象) Function is the object from which JavaScript functions are derived. Functions are first-class data types in JavaScript, so they may...

    js获取对象,数组所有属性键值(key)和对应值(value)的方法示例

    本文实例讲述了js获取对象,数组... for (var property in object) values.push(object[property]); return values; } //写成标准的方法(数组是object的一种): function getObjectKeys(object) { var keys = [];

    韩顺平培训学员面试资料涵盖Java+javascript

    通常情况下, JavaScript中建立一个对象用"new"加上constructor function来实现. 如new Date(), new Object()等. var book = new Object(); book.name = "JavaScript is Cool"; book.author = "tom"; book.pages = ...

    Composing Software: An Exploration of Functional Programming

    In “Composing Software”, Eric Elliott shares the fundamentals of composition, including both function composition and object composition, and explores them in the context of JavaScript. The book ...

    Javascript json object 与string 相互转换的简单实现

    Javascript json object 与string 相互转换的简单实现 function obj2str(o){ var r = []; if(typeof o == "string" || o == null) { return o; } if(typeof o == "object"){ if(!o.sort){ r[0]="{" for...

    JavaScript权威指南

    JavaScript in Other Contexts Section 1.5. Client-Side JavaScript: Executable Content in Web Pages Section 1.6. Client-Side JavaScript Features Section 1.7. JavaScript Security Section 1.8. ...

    javascript中将Object转换为String函数代码 (json str)

    代码如下: function obj2str(o){ var r = []; if(typeof o ==”string”) return “\””+o.replace(/([\’\”\\])/g,”\\$1″).replace(/(\n)/g,”\\n”).replace(/(\r)/g,”\\r”).replace(/(\t)/g,”\\t”)+”\”...

Global site tag (gtag.js) - Google Analytics