November 2007 - Posts
I love working with the new objects in JavaScript available in the AJAX framework. There is a new Sys.StringBuilder, which looks/acts/feels just like the server side StringBuilder does.
There is also an extension to String for a format(mask, [args]); method that let's you do a nice replacement of a string mask.
String.format("{0} is before {1}", "This", "That") give your a nice single string of "This is before That", just as you'd encounter on your Server side.
But Sys.StringBuilder doesn't have an appendFormat(mask, [args]) like String does, it only has a append, and an appendLine() method.
So let's create a new ScottCate.StringBuilder that inherits from Sys.StringBuilder, and prototype an appendFormat() on it.
I'm not very happy with the arg0....arg9 in the appendFormat() signature, but that was easier than reflection style code against the arguments.
Oh! And special thanks to my friend Michael, who helped me figure out the toString() problem I was having.
[UPDATE] Man-o-man you gotta love blogging. A few hours after I posted this, I received a tip about the Function.apply() method. I can't believe after all these years, I'm still finding these nuggets in JavaScript. apply() allows for the arguments that were passed into the method (err function) to be passed onto another method (I mean function). So now as many strings as I want to pass into appendFormat(), will all just get passed to String.format() and the whole thing is much nicer then when I started.
Type.registerNamespace('ScottCate');
ScottCate.StringBuilder = function(len) {
ScottCate.StringBuilder.initializeBase(this, [len]);
}
ScottCate.StringBuilder.prototype = {
appendFormat: function(mask) {
this.append(String.format.apply(null, arguments));
},
toString: function(delimeter) {
return ScottCate.StringBuilder.callBaseMethod(this,
"toString", [delimeter]);
}
}
ScottCate.StringBuilder.prototype = {
appendFormat: function(mask, arg0, arg1, arg2, arg3,
arg4, arg5, arg6, arg7, arg8, arg9) {
this.append(String.format(mask, arg0, arg1, arg2, arg3, arg4,
arg5, arg6, arg7, arg8, arg9));
},
toString: function(delimeter) {
return ScottCate.StringBuilder.callBaseMethod(this,
"toString", [delimeter]);
}
}
ScottCate.StringBuilder.inheritsFrom(Sys.StringBuilder);
ScottCate.StringBuilder.registerClass('ScottCate.StringBuilder',
Sys.StringBuilder);
function TestSB() {
var sb = new ScottCate.StringBuilder();
var mask = "{0} goes in front of {1}";
sb.appendFormat(mask, "This", "that");
alert(sb.toString());
}
[UPDATE2 2008 Sep 05] I've had two different code versions of this for a while, and the second prototype version of this is now posted online.
http://weblogs.asp.net/scottcate/archive/2008/09/05/sys-stringbuilder-appendformat-mask-args.aspx
The Road Code Trip is on. A few months ago I was hanging out at the ASP.NET User Group meeting in PHX ( www.azgroups.com ) and was brainstorming with Tim Heuer about a fun way to talk about new technology. There was all kinds of conversations about wild ideas, this and that.
It looks like the conversation continued, because now they have a site ( www.TheCodeTrip.com ) and an RSS feed for more information.
The Code Trip is a fun group of guys with a budget to entertain and the passion to teach. Spend some cash to draw geeks in to see/learn some new technology.
With all the new technology coming out these days, it seems like a great way for me to get an introduction into some of the things that I would otherwise not probably pay attention to. I try to stay up with asp.net - so the new stuff for me is 3.5 features, data fun with ado.net, and new services goop with WFC.
The schedule isn't posted, or even the route, but I have to assume they'll be cruising through PHX at some point, just because of the people involved.
This sounds like a fun ride. The site asks to submit ideas. I'm going to submit that they stop in Eloy and give away some sky diving packages :)
I'm also going to ask if I can ride along for a few portions of the trip. Not sure if there is room, those motor homes are usually pretty small, but hey - if you don't ask the answer is always "NO".
WOW! I've just started digging into the ASP.NET AJAX control toolkit animations. This thing is amazing, and at all the control toolkit conferences and talks, I've never seen this in action.
Well, that's not entirely true, I've see the UpdatePanelAnimcationExtender in action, but I had no idea that it was built on such a flexible <animations /> node.
What's your favorite resource online, that might be used to bring me up to speed on these animations? I must say the documentation is a great way to get started, but now that I've built a few animations, I'd love to learn-by-example with what other peeps have put together.
I've also scraped together a bit of knowledge from the debugger, but nothing as simple as just reading others examples.
Thanks for the feedback/comments.
Over the past few years, I've been speaking and conferences and user groups around North America on the the subject of Microsoft AJAX, and the ASP.NET AJAX Extensions.
If you've been to one of my talks, or read any of my material; first of all -- thank you for your time. I hope it was well spent, and that you were able to learn something.
Second, I've moved the example project I use from what was made available as a zipped file to CodePlex. This will make it much easier for people to follow, add, comment, report bugs, etc, and hopefully will help the project mature over time.
Depending on how this initial test works, my current plan is to make this a standard. Standard for me and my Conference/User group samples that is, I'm not trying to change the world here.
So if you're interested in a fully loaded project of working MS AJAX samples, check it out.
http://www.codeplex.com/ScottCateAjax
Enjoy!
More Posts