28 January 2015

XMLHttpRequest

JSONP

  • http://www.json-p.org/
  • http://en.wikipedia.org/wiki/JSONP

Function

RegExp

  • https://regex101.com/#javascript

Bower

Bootstrap

Build documentation, run jekyll build.

ECMAScript

Chrome

Hit Shift+Enter to input multiple lines of JavaScript code.

Hit F12 and check Disable cache in Network tab. Hit F5 only can refresh HTML loaded in Chome. To make sure that external JS used by the loaded HTML is refreshed, the following steps are needed. Take the following HTML as an example.

<html>
<head>
<script src="js/services.js"></script>
</head>
</html>
  • Right click to show up context menu
  • Click View page source
  • Open js/services.js in a new Chrome tab
  • Hit F5 in the new tab

History Cache

In Chrome, issue 1 qq.com, can’t connect 2 www.qq.com, show up. 3 qq.com, browse use www.qq.com automatically

AngularJS

[{name: ‘John’, no: 1}, {name: ‘Mike’, no: 2}] fitler filter. Object filter ‘filter: {no: 1}’ is equivalent to ‘filter: search.no’ if there is ‘’. JS built-in functions can be used inside an expression.

Use underscore Set up:

var underscore = angular.module('underscore', []);
underscore.factory('_', function() {
  return window._; // assumes underscore has already been loaded on the page
});

Use it:

// Declare it as a dependency of your module
var app = angular.module('app', ['underscore']);

// And then inject it where you need it
app.controller('Ctrl', function($scope, _) {
  // do stuff
});

$resource all returns a object or an array. $resource doc says:

It is important to realize that invoking a $resource object method immediately returns an empty reference (object or array depending on isArray).

@ in $resource will extract a property value. It will not remove the property from the object. For example, {id : '@id'} will extract id property from the following JSON object. And the whole JSON object will be sent untouched.

{
 id: 1,
 name: 'xiaoyu'
}

Protractor

console.log logs message to terminal console when running proractor.

CORS

Node

Installing Node.js via package manager will install an old version of Node. For new versions of Node, install from https://nodejs.org/.

Upgrade node:

sudo n stable
sudo npm install npm -g

REST API Design

  • http://docs.aws.amazon.com/AmazonS3/latest/API/ErrorResponses.html#RESTErrorResponses
  • https://developers.google.com/drive/v2/reference/

MISC

var myLog = console.log;
myLog('abc');

The above code works in Node. But in Chrome brower, there is the following error:

Uncaught TypeError: Illegal invocation

HTTP 301 Redirection

Chrome will cache HTTP 301 Redirection as long as it’s cache size is allowd. And a cached HTTP 301 Redirection will not shown up in Chrome Developer Tools’ network tab.

Resources

CSS