<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>lekkimworld.comjavascript</title>
    <link>http://lekkimworld.com/tags/javascript/</link>
    <description>IBM Lotus Notes/Domino, Websphere, IBM Connections, mobile, web, JavaScript, Java...</description>
    <language>en</language>
    <copyright>Mikkel Flindt Heisterberg (mh [at] intravision [dot] dk</copyright>
    <pubDate>Sat, 19 May 2012 06:50:25 GMT</pubDate>
    <dc:creator>Mikkel Flindt Heisterberg (mh [at] intravision [dot] dk</dc:creator>
    <dc:date>2012-05-19T06:50:25Z</dc:date>
    <dc:language>en</dc:language>
    <dc:rights>Mikkel Flindt Heisterberg (mh [at] intravision [dot] dk</dc:rights>
    <image>
      <title>lekkimworld.comjavascript</title>
      <url>http://lekkimworld.com/tags/javascript/</url>
    </image>
    <item>
      <title>Bookmark to IBM Connections bookmarks from iOS</title>
      <link>http://lekkimworld.com/2012/03/08/bookmark_to_ibm_connections_bookmarks_from_ios.html</link>
      <content:encoded>&lt;p&gt;
Bookmarks (aka Dogear) in IBM Connections is great and IBM provides a nifty bookmarklet to allow easy bookmarking from your browser. I couldn't however make this bookmarklet work in Safari on iOS so I decided to look into it. And I'm happpy to say I got it to working with some inspiration from &lt;a href="http://instapaper.com"&gt;the Instapaper bookmarklet&lt;/a&gt;. The way it works for me now is that I have the bookmark bar visible on my iPhone and iPad and when I need to bookmark I use the bookmarklet which redirects to the IBM Connections bookmark page and back to the original page once done. Super easy and it works great.
&lt;/p&gt;
&lt;p&gt;
Here is how to make it work.
&lt;ol&gt;
&lt;li&gt;Open Safari and make a bookmark to a random page but be sure to place it in the bookmark bar (the bookmark bar can be made visible all the time in Safari options).&lt;/li&gt;
&lt;li&gt;Edit that bookmark and change the title to something that makes sense (I use "IV Dogear").&lt;/li&gt;
&lt;li&gt;Clear the location field and paste in the JavaScript code from below replacing the hostname (lc.intravision.dk) with a hostname applicable to you.&lt;/li&gt;
&lt;li&gt;Save the bookmark and start bookmarking.&lt;/li&gt;
&lt;/ol&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;style type="text/css"&gt;
pre.wrap {
white-space: pre-wrap; /* css-3 */
white-space: -moz-pre-wrap !important; /* Mozilla, since 1999 */
white-space: -pre-wrap; /* Opera 4-6 */
white-space: -o-pre-wrap; /* Opera 7 */
word-wrap: break-word; /* Internet Explorer 5.5+ */
}
&lt;/style&gt;
&lt;pre class="wrap"&gt;
javascript:function%20abcdefg()%7Bvar%20h='http://lc.intravision.dk/dogear';var%20d=document;var%20b=d.body;var%20e=encodeURIComponent;var%20u=h+'/bookmarklet/post?url='+e(location.href)+'&amp;title='+e(d.title);location.href=u+'&amp;inframe=true&amp;ver=';%7D;abcdefg();void(0);
&lt;/pre&gt;
&lt;/p&gt;</content:encoded>
      <category domain="http://lekkimworld.com/tags/bookmarklet/">bookmarklet</category>
      <category domain="http://lekkimworld.com/tags/connections/">connections</category>
      <category domain="http://lekkimworld.com/tags/ibm_connections/">ibm_connections</category>
      <category domain="http://lekkimworld.com/tags/javascript/">javascript</category>
      <pubDate>Thu, 08 Mar 2012 09:01:00 GMT</pubDate>
      <guid isPermaLink="false">tag:lekkimworld.com,2012-03-08:default/1331197260328</guid>
      <dc:date>2012-03-08T09:01:00Z</dc:date>
    </item>
    <item>
      <title>If you're writing JavaScript this is a must read</title>
      <link>http://lekkimworld.com/2012/01/15/if_youre_writing_javascript_this_is_a_must_read.html</link>
      <content:encoded>&lt;p&gt;
Normally with a link like this I would put it on twitter but with Lotusphere 2012 underway it would get lost and it really it too important for that. If you're writing JavaScript - and who isn't - you really should read &lt;a href="http://killdream.github.com/blog/2011/10/understanding-javascript-oop/index.html"&gt;Understanding JavaScript OOP&lt;/a&gt; by Quildreen Motta. I really mean it! 
&lt;/p&gt;</content:encoded>
      <category domain="http://lekkimworld.com/tags/javascript/">javascript</category>
      <category domain="http://lekkimworld.com/tags/ls12/">ls12</category>
      <category domain="http://lekkimworld.com/tags/oop/">oop</category>
      <pubDate>Sun, 15 Jan 2012 19:05:06 GMT</pubDate>
      <guid isPermaLink="false">tag:lekkimworld.com,2012-01-15:default/1326654306031</guid>
      <dc:date>2012-01-15T19:05:06Z</dc:date>
    </item>
    <item>
      <title>More on the JavaScript Module Pattern</title>
      <link>http://lekkimworld.com/2011/10/23/more_on_the_javascript_module_pattern.html</link>
      <content:encoded>&lt;p&gt;
Annoter good post on the Module Pattern - this one being the original post as far as I can tell. &lt;a href="http://www.yuiblog.com/blog/2007/06/12/module-pattern/"&gt;A JavaScript Module Pattern&lt;/a&gt;.
&lt;/p&gt;</content:encoded>
      <category domain="http://lekkimworld.com/tags/javascript/">javascript</category>
      <category domain="http://lekkimworld.com/tags/oop/">oop</category>
      <category domain="http://lekkimworld.com/tags/pattern/">pattern</category>
      <pubDate>Sun, 23 Oct 2011 07:05:16 GMT</pubDate>
      <guid isPermaLink="false">tag:lekkimworld.com,2011-10-23:default/1319353516343</guid>
      <dc:date>2011-10-23T07:05:16Z</dc:date>
    </item>
    <item>
      <title>The JavaScript Module Pattern - adding namespace</title>
      <link>http://lekkimworld.com/2011/10/21/the_javascript_module_pattern_adding_namespace.html</link>
      <content:encoded>&lt;p&gt;
The Module Pattern has as added benefit of allowing you to add namespace to classes. The below extends the previous example to make the class COM.LEKKIMWORLD.ModuleAbc.  Very cool in my eyes and reduces the chance for name collisions much like with Dojo classes. 
&lt;pre&gt;
// Create a COM namespace
var COM = (function() {
  return {};
}());

// Create a LEKKIMWORLD namespace
COM.LEKKIMWORLD = (function() {
  return {};
}());

// Add a class called ModuleAbc to the COM.LEKKIMWORLD namespace
COM.LEKKIMWORLD.ModuleAbc = (function(secret) {
  // the object we're incapsulating
  var OBJ = {};

  // private variables (these are truely private and 
  // cannot be accessed from the outside)
  var secret = "my secret is: " 

  // my property
  OBJ.myproperty = "my property value";

  // echo method
  OBJ.echo = function(v) {
    return "Echo: " + v;
  };
  
  // return the object
  return OBJ;
  
});
&lt;/pre&gt;
&lt;/p&gt;</content:encoded>
      <category domain="http://lekkimworld.com/tags/javascript/">javascript</category>
      <category domain="http://lekkimworld.com/tags/module/">module</category>
      <category domain="http://lekkimworld.com/tags/oop/">oop</category>
      <pubDate>Fri, 21 Oct 2011 14:28:15 GMT</pubDate>
      <guid isPermaLink="false">tag:lekkimworld.com,2011-10-21:default/1319207295000</guid>
      <dc:date>2011-10-21T14:28:15Z</dc:date>
    </item>
    <item>
      <title>The JavaScript Module Pattern</title>
      <link>http://lekkimworld.com/2011/10/21/the_javascript_module_pattern.html</link>
      <content:encoded>&lt;p&gt;
If you are like me you like object oriented programming and you try to encapsulate the functionality to the best of your ability. And that goes for JavaScript as well of course. JavaScript pose an interesting problem though as JavaScript objects are as opaque as air that is you can see right through it.
&lt;/p&gt;
&lt;p&gt;
Normally an object in JavaScript - whether declared though dojo.declare or function/json isn't able to hide it's member variables at all. You can try with "this." or using _neverUser naming but fundamentally the "private" variables of a JavaScript class are available from the outside. Consider the below examples:
&lt;pre&gt;
// enter the dojo
var DojoAbc = dojo.declare(null, {
  constructor: function(secret) {
    this.mysecret = secret;
  },
  myproperty: "my property value", 
  echo: function(v) {
    return "Echo: " + v;
  }
});
var myDojoAbc = 
   new DojoAbc("my little secret");
alert(myDojoAbc.echo(new Date()));
alert(myDojoAbc.myproperty);
alert(myDojoAbc.mysecret);

// plain ol' JavaScript
var PlainAbc = function(secret) {
  this.mysecret = secret;
  this.myproperty = "my property value";
  this.echo = function(v) {
    return "Echo: " + v;
  }
};
var myPlainAbc = 
   new PlainAbc("my little secret");
alert(myPlainAbc.echo(new Date()));
alert(myPlainAbc.myproperty);
alert(myPlainAbc.mysecret);
&lt;/pre&gt;
In both examples the "mysecret" variable is accessible although I didn't mean it to. There is no way in the above example to make the mysecret-variable invisible to the outside. That is a user of your class can access it and see it using a JavaScript debugging such as Firebug.
&lt;/p&gt;
&lt;p&gt;
Bummer I thought. What then? How do I do it? Well I'm glad you asked as there is a way. It's called the Module Pattern. Let me show you but let me also warn you - it is a little conveluted to look at.
&lt;/p&gt;
&lt;p&gt;
The below code starts by creates a class like above but nothing besides the myproperty-property and the echo-method are available (even in Firebug) from the outside. So the last alert will actually say "undefined" as mysecret is available to the outside. It's super cool and it's the way I'm going to do my objects from now on.
&lt;pre&gt;
var ModuleAbc = (function(secret) {
  // the object we're incapsulating
  var OBJ = {};

  // private variables (these are 
  // truely private and cannot be 
  // accessed from the outside)
  var secret = "my secret is: " 

  // my property
  OBJ.myproperty = "my property value";

  // echo method
  OBJ.echo = function(v) {
    return "Echo: " + v;
  };
  
  // return the object
  return OBJ;
  
});

// use case
var myModuleAbc = 
   new ModuleAbc("my little secret");
alert(myModuleAbc.echo(new Date()));
alert(myModuleAbc.myproperty);
alert(myModuleAbc.mysecret);
&lt;/pre&gt;
&lt;/p&gt;
&lt;p&gt;
More information about the pattern incl. composition, inheritance etc. can be found on the the Adequately Good blog in the &lt;a href="http://www.adequatelygood.com/2010/3/JavaScript-Module-Pattern-In-Depth"&gt;JavaScript Module Pattern: In-Depth&lt;/a&gt; post.
&lt;/p&gt;
&lt;p&gt;
Have an excellent Friday.
&lt;/p&gt;</content:encoded>
      <category domain="http://lekkimworld.com/tags/javascript/">javascript</category>
      <category domain="http://lekkimworld.com/tags/module/">module</category>
      <category domain="http://lekkimworld.com/tags/oop/">oop</category>
      <pubDate>Fri, 21 Oct 2011 12:27:43 GMT</pubDate>
      <guid isPermaLink="false">tag:lekkimworld.com,2011-10-21:default/1319200063093</guid>
      <dc:date>2011-10-21T12:27:43Z</dc:date>
    </item>
    <item>
      <title>Power of the Javascript console</title>
      <link>http://lekkimworld.com/2011/10/17/power_of_the_javascript_console.html</link>
      <content:encoded>&lt;p&gt;
Dmytro Pastovenskyi blogged the other day about the power of the JavaScript console. Now the JavaScript console is a real timesaver for many types of JavaScript debugging but I never realized just how powerful it is. I recommend reading Dmytros blog post (&lt;a href="http://dpastov.blogspot.com/2011/10/javascript-use-power-of-console.html?utm_source=feedburner&amp;utm_medium=feed&amp;utm_campaign=Feed%3A+dpastov+%28Pastovenskyi+Dmytro%29"&gt;JavaScript: use power of console&lt;/a&gt;) and &lt;a href="http://www.google.dk/search?gcx=w&amp;sourceid=chrome&amp;ie=UTF-8&amp;q=javascript+console+object"&gt;googling "javascript console object"&lt;/a&gt;.
&lt;/p&gt;</content:encoded>
      <category domain="http://lekkimworld.com/tags/console/">console</category>
      <category domain="http://lekkimworld.com/tags/javascript/">javascript</category>
      <pubDate>Mon, 17 Oct 2011 11:04:23 GMT</pubDate>
      <guid isPermaLink="false">tag:lekkimworld.com,2011-10-17:default/1318849463796</guid>
      <dc:date>2011-10-17T11:04:23Z</dc:date>
    </item>
    <item>
      <title>A (dojo.)mixin configuration approach to XAgents in XPages</title>
      <link>http://lekkimworld.com/2011/05/11/a_dojo_mixin_configuration_approach_to_xagents_in_xpages.html</link>
      <content:encoded>&lt;p&gt;
Continuing my XPages theme from yesterday I also wrote an XAgent base-class in JavaScript to make XAgents easier to do. Part of the base class is that it allows me to pass in a JSON object to configure the XAgent based on the need. Since the information I pass in should override the built-in defaults I needed a way to easily allow the user supplied values to override the defaults. The easiest way to do this would be to use the &lt;a href="http://dojotoolkit.org/reference-guide/dojo/mixin.html"&gt;dojo.mixin&lt;/a&gt;. 
&lt;pre&gt;&lt;i&gt;"dojo.mixin is a simple utility function for mixing objects 
together. Mixin combines two objects from right to left, 
overwriting the left-most object, and returning the newly 
mixed object for use."&lt;/i&gt;&lt;/pre&gt;
Unfortunately Dojo isn't available in SSJS I needed to do it myself. To my luck it was surprisingly easy as the below code illustrates.
&lt;/p&gt;
&lt;p&gt;
&lt;pre&gt;
// create function to allow mixin' two objects
var mixin = function(target, source) {
   if (!source) return;
      var name, s, i;
      for (name in source) {
      s = source[name];
      if (!(name in target) || (target[name] !== s)) {
         target[name] = s;
      }
   }
};
&lt;/pre&gt;
&lt;/p&gt;
&lt;p&gt;
My XAgent base class looks something like this:
&lt;pre&gt;
function XAGENT(args) {
   // create mixin function
   var mixin = function(target, source) {
      if (!source) return;
         var name, s, i;
         for (name in source) {
         s = source[name];
         if (!(name in target) || (target[name] !== s)) {
            target[name] = s;
         }
      }
   };

   // define default arguments
   this._args = {
      download: false,
      filename: "default.json",
      charset: "iso-8859-1",
      contentType: "application/json"
   };
   
   // mixin user-supplies arguments
   mixin(this._args, args);
};
XAGENT.prototype.run = function(command) {
   ...
};
&lt;/pre&gt;
&lt;/p&gt;
&lt;p&gt;
What's super neat is that now, in my run-method I can access the this._args object and all values that the user supplied have overridden the default values because we used the mixin-function. Very cool and an easy and flexible way to have default values but allowing them to be overridden by the caller. Also you know that the variables you need have been defined so no checks are necessary.
&lt;/p&gt;
&lt;p&gt;
Calling my XAgent class is very easy allowing me to override the defaults. The run-method accepts a function which is called when the XAgent stuff has been set up supplying the Writer and the parameters supplied in the URL as a JSON object. 
&lt;pre&gt;
var xa = new XAGENT({
   filename: "feed.json", 
   download: true
});
xa.run(function(w, params) {
   ...
});
&lt;/pre&gt;
&lt;/p&gt;</content:encoded>
      <category domain="http://lekkimworld.com/tags/dojo/">dojo</category>
      <category domain="http://lekkimworld.com/tags/javascript/">javascript</category>
      <category domain="http://lekkimworld.com/tags/xagent/">xagent</category>
      <category domain="http://lekkimworld.com/tags/xpages/">xpages</category>
      <pubDate>Wed, 11 May 2011 15:14:51 GMT</pubDate>
      <guid isPermaLink="false">tag:lekkimworld.com,2011-05-11:default/1305126891125</guid>
      <dc:date>2011-05-11T15:14:51Z</dc:date>
    </item>
    <item>
      <title>XPages JavaScript utility function of the day</title>
      <link>http://lekkimworld.com/2011/05/10/xpages_javascript_utility_function_of_the_day.html</link>
      <content:encoded>&lt;p&gt;
Yesterday and today I've been spending some time doing some XPages coding for a customer project and after spending quite some time doing Java plugin development I'm amazed of how easy XPages are. Don't get me wrong - there is still work to do for the XPages team but it's a joy to work with XPages and coding in JavaScript is just - well - flexible and fun.
&lt;/p&gt;
&lt;p&gt;
One of the real joys of JavaScript is it's dynamic nature and that it allows one to really cut down on the boilerplate and repeated code. For one I spent a lot of key pressed getting field values from backend documents in server side JavaScript. Instead of repeating the same ol' Document.getItemValueString(String) over and over again I did a neat little shortcut. Since I needed all items from a document I just created a utility function to JSONify a document to make it easier to access. The method is below.
&lt;/p&gt;
&lt;p&gt;
&lt;pre&gt;
var jsonifyDocument = function(doc) {
   var result = {};
   if (!doc) return result;
   var item;
   for (item in doc.getItems().toArray()) {
      result[item.getName().toLowerCase()] = item.getText();
   }
   return result;
};
&lt;/pre&gt;
So now instead of writing doc.getItemValueString all the time I can now just do property-like access to field values ("Heading" and "Description" are fields on the document). 
&lt;pre&gt;
var jsonDoc = jsonifyDocument(doc);
jsonDoc.heading + " (" + jsonDoc.description + ")";
&lt;/pre&gt;
&lt;/p&gt;
&lt;p&gt;
I also wrote a nice little Dojo-like mixin function to make my XAgents easy to configure. But that's for another day.
&lt;/p&gt;</content:encoded>
      <category domain="http://lekkimworld.com/tags/dojo/">dojo</category>
      <category domain="http://lekkimworld.com/tags/javascript/">javascript</category>
      <category domain="http://lekkimworld.com/tags/json/">json</category>
      <category domain="http://lekkimworld.com/tags/xagent/">xagent</category>
      <category domain="http://lekkimworld.com/tags/xpages/">xpages</category>
      <pubDate>Tue, 10 May 2011 12:05:02 GMT</pubDate>
      <guid isPermaLink="false">tag:lekkimworld.com,2011-05-10:default/1305029102437</guid>
      <dc:date>2011-05-10T12:05:02Z</dc:date>
    </item>
  </channel>
</rss>


