MyFunnyDev

web, coding and beyond

Archive for October, 2009

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

Gemcutter & Jeweler

without comments

More about gemcutter & jeweler can be found here.

Here are the steps how to publish patched gem cloned from github:

1. Append username to gem name in .gemspec or if you use jeweler open Rakefile and edit Jeweler::Tasks section save it and run:

rake gemspec

2. Build gem with:

gem build

3. Push new gem to gemcutter

gem push

Written by Michał Kuklis

October 17th, 2009 at 1:03 am

Posted in Uncategorized

Tagged with