Back to top.
Loading...
Posts tagged javascript.
6 Advanced JavaScript Techniques You Should Know
02.22.13 2
GNOME recomienda javaScript para construir aplicaciones en GNOME
02.06.13 0
Event Pooling with jQuery Using Bind and Trigger: Managing Complex Javascript
02.04.13 0
A Bit of Advice for the JavaScript Semicolon Haters
01.26.13 0
JavaScript Date Format

var now = new Date();

now.format("m/dd/yy");
// Returns, e.g., 6/09/07

// Can also be used as a standalone function
dateFormat(now, "dddd, mmmm dS, yyyy, h:MM:ss TT");
// Saturday, June 9th, 2007, 5:46:21 PM

// You can use one of several named masks
now.format("isoDateTime");
// 2007-06-09T17:46:21

// ...Or add your own
dateFormat.masks.hammerTime = 'HH:MM! "Can\'t touch this!"';
now.format("hammerTime");
// 17:46! Can't touch this!

// When using the standalone dateFormat function,
// you can also provide the date as a string
dateFormat("Jun 9 2007", "fullDate");
// Saturday, June 9, 2007

// Note that if you don't include the mask argument,
// dateFormat.masks.default is used
now.format();
// Sat Jun 09 2007 17:46:21

// And if you don't include the date argument,
// the current date and time is used
dateFormat();
// Sat Jun 09 2007 17:46:22

// You can also skip the date argument (as long as your mask doesn't
// contain any numbers), in which case the current date/time is used
dateFormat("longTime");
// 5:46:22 PM EST

// And finally, you can convert local time to UTC time. Either pass in
// true as an additional argument (no argument skipping allowed in this case):
dateFormat(now, "longTime", true);
now.format("longTime", true);
// Both lines return, e.g., 10:46:21 PM UTC

// ...Or add the prefix "UTC:" to your mask.
now.format("UTC:h:MM:ss TT Z");
// 10:46:21 PM UTC

10.18.12 0
Currying in JavaScript

Needed to make an array of functions, but certain parameter has to vary inside the function:

// The array containing the elements each for every functon
var comments = ['1', '2', '3', '4', '5']

// The function with the different element
function saveComment (callback, i) {
  console.log(comments[i]);
  callback();
}

// Wrapper, (or `currier`)
function fn (i) {
  return function (callback) {
    return saveComment (callback, i);
  };
};

// The array containing the functions
var myArray = [];

// The loop to compose them
for (var j = 0; j < 5; j ++) {
  var saveCommentForI = fn(j);
  myArray.push(saveCommentForI);
};

// Executing our array of functions
for (var k = 0; k < 5; k++) {
  myArray[k](function(){
    console.log('callback invoked')
  });
};

/**
  Result should be:

  $ node test.js
 
  1
  callback invoked
  2
  callback invoked
  3
  callback invoked
  4
  callback invoked
  5
  callback invoked

 */

gist

10.08.12 0
JavaScript - Function call() and Function apply()
10.07.12 0
Accessing Arguments Using the Arguments Object
function containerScope(){
var a = []; var b = {}; var c = true; var d = 22; function argumentsObject(a, b, c, d){ console.log(arguments.length); console.log(arguments[0]);//Array console.log(arguments[1]);//Object console.log(arguments[2]);//true console.log(arguments[3]);//22 arguments[3] = 55;//I have now changed d as well! console.log(arguments[3]); console.log(d); } argumentsObject(a, b, c, d); }

via SNIPPLR

10.04.12 0
Date.now() doesn’t work in IE 8 (or earlier)

This is the workaround:

// For IE8 and earlier version.
if (!Date.now) {
  Date.now = function() {
    return new Date().valueOf();
  }
}

source: Here

09.03.12 0
Javascript - How to check a not defined variable

If you want to check if a variable exist

if (typeof yourvar != 'undefined') // Any scope
if (window['varname'] != undefined) // Global scope
if (window['varname'] != void 0) // Old browsers

via Stackoverflow

08.28.12 0
The tilde ( ~ ) operator in JavaScript
04.08.12 0
Javascript: Converting Numbers to Strings

Add an empty string to your number:

> my_number = 323
> my_array = my_number+''
> typeof(my_array)
string
> typeof(1974689+'')
string
> my_number = 159627221
> typeof(my_number)
number
> my_number = my_number + ''
159627221
> typeof(my_number)
string

That’s going straight to the KISS awards

via javascripter.net

03.09.12 0

universalruntime:

NoFlo - Managing workflows with JavaScript. My presentation from the Boston JS.Everywhere conference.

The slides are also available.

12.11.11 1
Top Story: Fast Auto Suggest with Redis

top10blog:

As part of our efforts to make list creation a simple experience, we have provided an auto suggest on certain fields when creating and remixing a Top10 since day one.

We initially tried several third party packages, but soon found out that none fitted with our expectations in either speed…

09.15.11 13
Asynchronous Programming in JavaScript with “Promises”

sambervalley:

Asynchronous patterns are becoming more common and more important to moving web programming forward. They can be challenging to work with in JavaScript. To make asynchronous (or async) patterns easier, JavaScript libraries (like jQuery and Dojo) have added an abstraction called promises (or sometimes deferreds). With these libraries, developers can use promises in any browser with good ECMAScript 5 support. In this post, we’ll explore how to use promises in your web applications using XMLHttpRequest2 (XHR2) as a specific example. Benefits and Challenges with Asynchronous Programming As an example, consider a web page that starts an asynchronous operation like XMLHttpRequest2 (XHR2) or Web Workers. There’s a benefit as some work happens “in parallel.” There’s complexity for the developer to keep the page responsive to people and not block human interaction while coordinating what the web page is doing with the asynchronous work. There’s complexity because program execution no longer really follows a simple linear path.

09.13.11 1