This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var users = []; | |
var userNodes = responseXML.getElementsByTagName('users'); | |
var node, usernameNodes, usernameNode, username, | |
realnameNodes, realnameNode, realname, | |
emailNodes, emailNode, email; | |
for (var i = 0, len = userNodes.length; i < len; i++) { | |
node = userNodes[i]; | |
username = realname = email = ''; | |
usernameNodes = node.getElementsByTagName('username'); | |
if (usernameNodes && usernameNodes[0]) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function xhrPost(url, params, callback) { | |
var req = new XMLHttpRequest(); | |
req.onerror = function() { | |
setTimeout(function() { | |
xhrPost(url, params, callback); | |
}, 1000); | |
}; | |
req.onreadystatechange = function() { | |
if (req.readyState == 4) { | |
if (callback && typeof callback === 'function') { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var req = new XMLHttpRequest(); | |
var getLatestPacketInterval, lastLength = 0; | |
req.open('GET', 'rollup_images.php', true); | |
req.onreadystatechange = readyStateHandler; | |
req.send(null); | |
function readyStateHandler{ | |
if (req.readyState === 3 && getLatestPacketInterval === null) { | |
// Start polling. | |
getLatestPacketInterval = window.setInterval(function() { | |
getLatestPacket(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function handleImageData(data, mimeType) { | |
var img = document.createElement('img'); | |
img.src = 'data:' + mimeType + ';base64,' + data; | |
return img; | |
} | |
function handleCss(data) { | |
var style = document.createElement('style'); | |
style.type = 'text/css'; | |
var node = document.createTextNode(data); | |
style.appendChild(node); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var url = '/data.php'; | |
var params = [ | |
'id=934875', | |
'limit=20' | |
]; | |
var req = new XMLHttpRequest(); | |
req.onreadystatechange = function() { | |
if (req.readyState === 4) { | |
var responseHeaders = req.getAllResponseHeaders(); // Get the response | |
headers. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function moveon() { | |
// Display a modal dialog to ask the user a question | |
var answer = confirm(“Ready to move on?”); | |
// If they clicked the “OK” button, make the browser load a new page | |
if (answer) window.location = “http://google.com“; | |
} | |
// Run the function defined above 1 minute (60,000 milliseconds) from now. | |
setTimeout(moveon, 60000); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// effectively equivalent to /^.{10}$/ | |
let hasLengthOf10 = { | |
[Symbol.match]: function(value) { | |
return value.length === 10 ? [value.substring(0, 10)] : null; | |
}, | |
[Symbol.replace]: function(value, replacement) { | |
return value.length === 10 ? replacement + value.substring(10) : value; | |
}, | |
[Symbol.search]: function(value) { | |
return value.length === 10 ? 0 : -1; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getFlags(re) { | |
var text = re.toString(); | |
return text.substring(text.lastIndexOf("/") + 1, text.length); | |
} | |
// toString() is "/ab/g" | |
var re = /ab/g; | |
console.log(getFlags(re)); // "g" | |
let re = /ab/g; | |
console.log(re.source); // "ab" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let text = "hello1 hello2 hello3", | |
pattern = /hello\d\s?/, | |
result = pattern.exec(text), | |
globalPattern = /hello\d\s?/g, | |
globalResult = globalPattern.exec(text), | |
stickyPattern = /hello\d\s?/y, | |
stickyResult = stickyPattern.exec(text); | |
console.log(result[0]); | |
console.log(globalResult[0]); | |
console.log(stickyResult[0]); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//The codePointAt() Method | |
let text = "𠮷"; | |
console.log(text.length); | |
console.log(/^.$/.test(text)); | |
console.log(text.charAt(0)); | |
console.log(text.charAt(1)); | |
console.log(text.charCodeAt(0)); | |
console.log(text.charCodeAt(1)); | |
let text = "𠮷a"; |