Archive for October, 2009
changing function’s context in javascript
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.
Gemcutter & Jeweler
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