io.js

Node.js简介及如何学习Node.js

核能气质少年 提交于 2020-08-04 15:40:41
本文介绍Node.js的诞生史以及如何学习Node.js。 Node.js简史 从Node.js的命名上可以看到,Node.js的官方开发语言是JavaScript。之所以选择使用JavaScript,显然与JavaScript的开发人员多有关。总所周知,JavaScript是伴随着互联网的发展而火爆起来的,JavaScript也是前端开发人员必备的技能。同时,JavaScript也是浏览器能直接运行的脚本语言。 但也正是JavaScript在浏览器端的强势,导致了人们对于JavaScript的印象还停留在小脚本的角色,认为JavaScript只能干点前端展示的简单活。 直到Chrome V8引擎( https://v8.dev/ )的出现,让JavaScript彻底翻了身。Chrome V8是JavaScript渲染引擎,第一个版本随着Chrome浏览器的发布而发布(具体时间为2008年9月2日)。在运行JavaScript之前,相比其它的JavaScript的引擎转换成字节码或解释执行,Chrome V8将其编译成原生机器码(IA-32、x86-64、ARM或者MIPS CPUs),并且使用了如内联缓存等方法来提高性能。Chrome V8可以独立运行,也可以嵌入到C++应用程序中运行。 随着Chrome V8引擎的声名鹊起,在2009年,Ryan

JS两种同步写异步的方法

夙愿已清 提交于 2020-05-06 11:52:38
async/await https://javascript.info/async-await 需要浏览器支持,后者使用webpack转换为ES5. There’s a special syntax to work with promises in a more comfortable fashion, called “async/await”. It’s surprisingly easy to understand and use. Async functions Let’s start with the async keyword. It can be placed before a function, like this: async function f ( ) { return 1 ; } The word “async” before a function means one simple thing: a function always returns a promise. Other values are wrapped in a resolved promise automatically. For instance, this function returns a resolved promise with the result of 1 ; let’s

Express 4 middleware not calling routes on DigitalOcean server

穿精又带淫゛_ 提交于 2019-12-13 18:16:05
问题 I'm messing around with creating an API with io.js and Express 4, and I have no idea why this isn't working. I am currently running the program on a DigitalOcean droplet (Ubuntu 14.04) and it is not calling the next() method never gets called/executed. The program is being routed to by a reverse proxy with nginx at https://<redacted>/asdf . var express = require('express'); var app = express(); var port = process.env.PORT || 3000; var router = express.Router(); router.use(function(req, res,

How to use ES6 Hash Map on any object without maintaing a reference (I.e. Java hashcode)

无人久伴 提交于 2019-12-11 02:32:38
问题 I've been experimenting with ES6 Map in io.js and realized that I can't do the following: var map = new Map() map.set( {key:"value"}, "some string"); map.get( {key:"value"} ); // undefined. I want "some string" This is because {key:"value"} === {key:"value"} is false. I need to be able to use an object as a key but not require the ACTUAL object to lookup the value like how java HashMap uses hashcode and equals. Is this possible? 回答1: If the lack of object identity stems from a serialize

Is there a reliable way of detecting whether io.js or node.js is running?

柔情痞子 提交于 2019-12-10 03:52:17
问题 The only way I can kind-of infer whether node.js or io.js is running is to check process.versions.node . In io.js, I get 1.0.4. I'm sure there's a better way - anyone know? 回答1: Now the most reliable solution is to exec node -h and see if it contains iojs.org substring. If it does - it's iojs : function isIojs(callback) { require('child_process').exec(process.execPath + ' -h', function(err, help) { return err ? callback(err) : callback(null, /iojs\.org/.test(help)); }); } The big minus of

How to run Express on io.js

爷,独闯天下 提交于 2019-12-08 10:47:31
问题 So Node.js was forked late last year and the forked version is io.js. I can't find anything of a setup guide on the docs. I'm fairly new, anyone know how I can setup io.js using Express web framework? Thanks! 回答1: Actually io.js wasn't released yet. First release will be at January 13th(or 14rth) (see here). At this time the best you can do to setup io.js is to clone its repository: git clone https://github.com/iojs/io.js and try to build it manually. On Unix/Max it looks like: ./configure

use of smalloc in io.js

我只是一个虾纸丫 提交于 2019-12-07 02:03:55
问题 The first release for io.js is out this month, I was reading the docs when I found smalloc a new module introduced in io.js. Till today I have never felt a need of doing so in JavaScript. My questions are: I wonder if there is really a need of raw memory allocation in javscript using smalloc ? If its needed then why? what would be the use case for using smalloc ? and if not then why did io.js members add this module? It also says It's possible is to specify the type of external array data you

ReactNative: Android与iOS平台兼容处理

♀尐吖头ヾ 提交于 2019-12-06 01:42:27
方法一: 创建不同的文件扩展名: *.android.js *.io.js 方法二: import { Platform } from 'react-native'; if (Platform.OS === 'android') { // Do something specific for Android } else if (Platform.OS === 'ios') { // Handle iOS } marginTop: Platform.OS === 'ios' 10 : 0, paddingBottom: Platform.OS === 'android' 8 : 0 方法三: const myStyle = Platform.select({ios:{},android:{}) const myFn = Platform.select({ios:()=>{},android:()=>{}) myFn(); 方法四: if (UIManager.setLayoutAnimationEnabledExperimental) { UIManager.setLayoutAnimationEnabledExperimental(true); } 来源: https://my.oschina.net/u/4225199/blog/3135188

use of smalloc in io.js

痞子三分冷 提交于 2019-12-05 07:45:30
The first release for io.js is out this month, I was reading the docs when I found smalloc a new module introduced in io.js. Till today I have never felt a need of doing so in JavaScript. My questions are: I wonder if there is really a need of raw memory allocation in javscript using smalloc ? If its needed then why? what would be the use case for using smalloc ? and if not then why did io.js members add this module? It also says It's possible is to specify the type of external array data you would like. All possible options are listed in smalloc.Types . Example usage: var doubleArr = smalloc

const vs let when calling require

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-03 04:43:28
问题 As io.js now supports ES6 you are finally able to use the const and let keywords. Obviously, let is the successor of var , just with some super-powers. But what about const ? I know, of course, what "constant" means, but I was wondering when to use it (regarding best practices). E.g., if I create a module that requires another module, I could write: 'use strict'; const util = require('util'); const foo = function () { // Do something with util }; module.exports = foo; Basically I've replaced