js基础知识(pomelo阅读)
2013-11-05 08:58
190 查看
0,node.js调试:
http://www.noanylove.com/2011/12/node-the-inspector-debugging-node-js/
1,读取配置文件:
官网描述:
If the exact filename is not found, then node will attempt to load the required filename with the added extension of
所以直接写一个json的配置文件用require就可以读入直接变成对象使用了,很方便。
关于node.js的模块加载机制: http://www.infoq.com/cn/articles/nodejs-module-mechanism
2,关于js中function的参数
The
OR
3,查看对象所有属性
log调试的时候想看一个对象的全部属性,所以:
4,js中双叹号:
相当于三元运算符,返回boolean值。
原理:第一个感叹号是将其转化成Boolean类型的值,但是这一操作得到的是其取反以后的值,在进行一次取反运算才能得到其对应真正的布尔值
等价于:
例子:
http://www.noanylove.com/2011/12/node-the-inspector-debugging-node-js/
1,读取配置文件:
var json = require('./configs/hot_deployer.json')
官网描述:
If the exact filename is not found, then node will attempt to load the required filename with the added extension of
.js,
.json, and then
.node
.jsfiles are interpreted as JavaScript text files, and
.jsonfiles are parsed as JSON text files.
.nodefiles are interpreted as compiled addon modules loaded with
dlopen.
所以直接写一个json的配置文件用require就可以读入直接变成对象使用了,很方便。
关于node.js的模块加载机制: http://www.infoq.com/cn/articles/nodejs-module-mechanism
2,关于js中function的参数
arguments
arguments本身并不是数组而是对象,所以想按照数组一样操作它,需要转换,下面是MDN上的解释:
The
argumentsobject is not an
Array. It is similar to an
Array, but does not have any
Arrayproperties except
length. For example, it does not have the
popmethod. However it can be converted to a real
Array: (转化成数组的方式)
var args = Array.prototype.slice.call(arguments);
OR
var args = [].slice.call(arguments);
3,查看对象所有属性
log调试的时候想看一个对象的全部属性,所以:
var array = []; for(var o in msg){ array.push(o); } console.log(array.join('\n'));
4,js中双叹号:
相当于三元运算符,返回boolean值。
原理:第一个感叹号是将其转化成Boolean类型的值,但是这一操作得到的是其取反以后的值,在进行一次取反运算才能得到其对应真正的布尔值
var ret = !!document.getElementById
等价于:
var ret = document.getElementById ? true : false;
例子:
var a = " "; alert(!!a); //true var a = "s"; alert(!!a); //true var a = true; alert(!!a); //true var a = 1; alert(!!a); //true var a = -1; alert(!!a); //true var a = -2; alert(!!a); //true var a = 0; alert(!!a); //false var a = ""; alert(!!a); //false var a = false; alert(!!a); //false var a = null; alert(!!a); //false
其他技巧:
var1+""转为string ~~var1转为int 1*var1转为float [var1]转为array
5,三等号
=:赋值,在逻辑运算时也有效; ==:等于运算,但是不比较值的类型; ===:完全等于运算,不仅比较值,而且还比较值的类型,只有两者一致才为真。
相关文章推荐
- (pomelo系列入门教材)深入浅出node.js游戏服务器开发1——基础架构与框架介绍
- js 基础知识
- H5基础知识第九课时(JS循环语句)
- Js基础知识梳理系列(01):数据类型
- JS基础知识(作用域/垃圾管理)
- js基础知识大总结
- js-ajax相关基础知识整理
- Js基础知识
- C++ primer plus 阅读记录-基础知识
- 【黑马程序员】JS基础知识
- KnockoutJS基础知识(一)
- NodeJs>------->>第三章:Node.js基础知识
- Node.js(基础知识二)
- H5基础知识第十一课时(JS查看节点)
- JavaScript 入门基础知识 想学习js的朋友可以参考下
- js基础碎片知识
- [阅读笔记] Content Deployment完全指南 之二 基础知识继续
- Node.js学习--基础知识(9)--HTTP服务器
- JavaScript学习笔记(一)——JS基础知识介绍
- JS操作DOM对象——JS基础知识(四)