MyFunnyDev

web, coding and beyond

Archive for the ‘Javascript’ Category

changing function’s context in javascript

without comments

Today I learned how to change the context of a function in javascript. When we do:

function test() {
  this.foo = "Hello from " + this + " context.";
}
test();
alert(foo); // will show "Hello from [object Window] context.";

foo will belong to the global context. In other words global object foo will be created. We can change the context to some other object by doing:

var otherContext = {};
test.call(otherContext);
alert(otherContext.foo); // will show "Hello from [object Object] context."

In this case foo will belong to otherContext.

Written by Michał Kuklis

October 31st, 2009 at 12:24 am

Posted in Javascript

JQuery 1.3

without comments

New release contains new selector engine called Sizzle (the fastest css selector out there) and live events (which work similar to the live query plugin).

More details can be found here

Written by Michał Kuklis

January 15th, 2009 at 8:51 pm

Posted in Javascript

Tagged with

Peppy fast css3 selector engine

without comments

Peppy is a small and very fast css3 selector written by James Donaghue. Here is how you can use it:

var selector = "div";
var context = "#elementId";
var q = peppy.query(selector, context);

Written by Michał Kuklis

October 28th, 2008 at 7:41 pm

Posted in Javascript

Tagged with

JavaScript closures

without comments

Nice presentation about JavaScript closures posted by Stuart Langridge

Written by Michał Kuklis

September 16th, 2008 at 7:30 pm

Posted in Javascript

Tagged with

Live Query plugin for jquery

with 3 comments

It’s annoying to rebind events to their targets after Ajax request. You can read more about it here.

In order to fix it you can use Live Query plugin.

Instead of doing:

$('a').click(dosomething);
$('#htmlElement').load('server.php',function() {
  $('a').click(dosomething);
});

you can now do:

$('a').livequery('click',dosomething);
$('#htmlElement').load('server.php');

Written by Michał Kuklis

December 16th, 2007 at 2:12 pm

Posted in Javascript, jquery

Tagged with

javascript essentials

without comments

Dan Webb posted his list of useful javascript pieces. I have to admit that $(), event handler and getting elements by class name makes your life easier. I would add JQuery to this list, especially when you have some bigger project in mind.

Written by Michał Kuklis

January 14th, 2007 at 8:40 pm

Posted in Ajax, Javascript

JQuery

without comments

Have you had a chance to play with JQuery? You can find it here. There is growing number of plugins here. Great job guys!

Written by Michał Kuklis

October 3rd, 2006 at 2:51 pm

Posted in Ajax, Javascript

Tagged with