Archive for the ‘JavaScript’ Category

WinJS.Class – unexpected behavior – watch out

January 3, 2013

What would you expect the code below to produce for value of ‘len’? If you said 1, then you, like me, are incorrect! In fact the value is 2. The problem here is that instance members get added to the prototype. So the array ‘test’ gets added to the prototype and both instances of TestClass are working on the same array. This seems very strange and is not clear from the documentation at: WinJS.Class.define. To avoid this issue, the test array must be initialized in the constructor.

var TestClass = WinJS.Class.define(function () {
// constructor
}, {
// instance members
test: []
}, {
// static members

var test1 = new TestClass();
var test2 = new TestClass();
var len = test2.test.length;


Deploy windows 8 app from the command line

May 12, 2012

I was developing a Windows 8 Metro JavaScript app and wanted to get the command line equivalent of Visual Studio “Build -> Deploy Solution”.

Simply do: devenv mysolution.sln /deploy “Release|x86” /project myproject.jsproj /projectconfig “Release|x86”

The result is located in bin/x86/Release/AppX.

This is nice because the result includes the code for the all references.  It also creates a combined .pri (resouces) file.