js回调函数2

  使用sublime结合node.js来写js代码特别爽,具体网上有教程。详见:http://blog.csdn.net/dududu01/article/details/42804367 ,其中最主要的是在

菜单 Tools --> Build System --> new Build System... 
中文版的话是 工具 --> 编译系统 --> 新建编译系统...

下写入一些代码以实现直接用sublime进行代码调试,具体代码如下:

{
    "cmd": ["node", "$file"],
    "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
    "working_dir": "${project_path:${folder}}",
    "selector": "source.js",
    "shell": true,
    "encoding": "utf-8",
    "windows": {
        "cmd": ["taskkill /f /im node.exe >nul 2>nul & node", "$file"]
    },
    "linux": {
        "cmd": ["killall node; node", "$file"]
    }
}

  然后按ctrl+b就可以直接运行js代码,而不需要把js结合html进行调试运行。

今天又复习了下js的回调函数,具体代码如下:

function w(callback2,sth){
	sth += ' very cool';
	callback2(sth);
}

w(function(sth){
	console.log(sth);
},'W大爷')

  其实很简单,运行结果如下图:

posted @ 2015-07-04 23:33  Sunor  阅读(551)  评论(0编辑  收藏  举报