Life, Arts and Technologies

Latest

How to Check Empty JQuery Object?

There are two ways of checking if a jQuery object is empty:

1.$.isEmptyObject(), or
2.$.length == 0
Since all custom object in javascript can be considered as hashtable this implies that each custom object comes with length property. To understand this let’s consider a simple javascript code bellow. If we inspect “div” value in Watch window, it clearly shows that div is a hashtable.

empty-jquery-object

Object Prototype

Say suppose that we have following function declaration:

function Person()
{
   this.surname = "zainal";
   this.givenname = "aripin";
}

Person.prototype.city = "sidoarjo";

//instantiate object
var aPerson = new Person();

If we run this script in Mozilla and turn the Firebug on then we should be able to see all properties and their values of the inspected object. By inspecting the Person object we’ll find an interesting property:

proto

What’s the __proto__ property anyway? The __proto__ here is used to explain the prototype chain; this property is not available in the language itself. In some browser (like Firefox) this property is representation of [[Prototype]] hidden property which is part of the ECMAScript specification.

The prototype gives us the flexibility to add behavior of new object. A prototype is an object and
every function we create automatically gets a prototype property that points to a new blank object. This object is almost identical to an object created with an object literal or Object() constructor, except that its constructor property points to the function we create and not to the built-in Object().

Since prototype is an object we can assign it to any kind of javascript object.

Person.prototype = {
	firstname : "zainal",
	lastname : "aripin",
	show: function () {
		alert(this.firstname + ' ' + this.lastname)
	}
}

var bPerson = new Person();
bPerson.show(); // shows "zainal aripin"

What happens to the object if the prototype is assigned by new value after object instantiation? This object will still retain the original prototype behavior. Consider following example:


function Person()
{
   this.surname = "zainal";
   this.givenname = "aripin";
}

Person.prototype.city = "sidoarjo";

//instantiate object
var aPerson = new Person();

Person.prototype = {
	firstname : "zainal",
	lastname : "aripin",
	show: function () {
		alert(this.firstname + ' ' + this.lastname)
	}
}

alert(aPerson.firstname); // undefined

The prototype assignment will add new behavior to the existing properties and functions instead of overwriting it.


function Person()
{
   this.surname = "zainal";
   this.givenname = "aripin";
}

Person.prototype.city = "sidoarjo";

Person.prototype = {
	firstname : "zainal",
	lastname : "aripin",
	show: function () {
		alert(this.firstname + ' ' + this.lastname)
	}
}

var aPerson = new Person();
alert(aPerson.surname); //zainal
alert(aPerson.givenname); //aripin
alert(aPerson.city); //sidoarjo
alert(aPerson.firstname); //zainal
alert(aPerson.lastname); //aripin

Variable in Javascript

Variable Types

Javascript is just like any other programming language has notation of variable. There are two types of Javascript variables:

  1. Primitive
  2. Object

There are only five primitives in Javascript: number, string, boolean, null and undefined . The object itself is categorised into two types of objects:

  1. Native, which is defined by ECMAScript
  2. Host, defined by the host/browser environment

The native object comprises the built-in object like Object, Array, Date etc or user-defined (literal) object such as: var x = {};.
Host object are for example window and DOM objects.

I’m Sorry There Is No Class

Surprisingly Javascript doesn’t come with the class notation. Programmers coming from OO background might find this bit confusing. However Javascript provides several ways to instantiate an object.

  1. Literal declaration ({}).
  2. new keyword.
  3. Object.create()

Object

The simplest way to think about object in Javascript is by imagining it as a hash table with key-value pair. The value can be a primitive or an object (property), or it can be a function (method). An object is represented by following rules:

  1. Wrap the object in curly braces ({ and }).
  2. Comma-delimit the properties and methods inside the object. A trailing comma after the last name-value pair is allowed but produces errors in IE, so don’t use it.
  3. Separate property names and property values with a colon.
  4. When you assign the object to a variable, don’t forget the semicolon after the closing }.

This can be exemplified by following code:

var Empty = {} // this will create an empty object
var Person = {surname:"zainal", givenname:"aripin"}; // this will create a person object with surname and given name properties

An object is not immutable. This means we can add property and method in any time we like.

var Person = {surname:"zainal", givenname:"aripin"};
Person.city = "sidoarjo"; //this will add city property to Person object

Another way to add a property and method is by using prototype

function Person()
{
   this.surname = "zainal";
   this.givenname = "aripin";
}

Person.prototype.city = "sidoarjo";

//instantiate object
var aPerson = new Person();
alert(aPerson.surname); //zainal
alert(aPerson.givenname); //aripin
alert(aPerson.city); //sidoarjo

We will come into prototype and its definition in a great detail. As of now we can think prototype is a way to add properties and methods to an object.

My First Javascript Post

This is a self invoked code:

(function($arg) {
   alert($arg);
})('Hello world');

Lahan Baru Untuk Penggilingan

Ranu Pane

Pantai Lumajang

Instalasi Web Client Software Factory (WCSF)

pnp.gif

Web Client Software Factory (WCSF) merupakan gabungan beberapa package/library . Untuk step-step instalasi sebenarnya anda dapat temukan Getting Started with the Web Client Software Factory . Namun saya akan menjelaskan lebih detail dan tentunya dalam bahasa Indonesia :).

Berikut ini merupakan langkah-langkah dan yang dibutuhkan untuk instalasi WCSF:

  1. Menginstall Visual Studio 2005
  2. Visual Studio 2005 Service Pack 1 (SP1)
  3. Guidance Automation Extension
  4. Menginstall WCSF

WCSF yang akan kita gunakan adalah release bulan January 2007. Sebenarnya versi terbaru bulan Juni sudah direlease. Namun mengingat masih baru dan belum banyak teruji lebih baik saya pergunakan release January 2007.

Setelah anda mempersiapkan Visual Studio 2005 yang diminta, maka langkah selanjutnya adalah mengikuti langkah-langkah berikut. Yang perlu diingat semua langkah dibawah ini harus dilakukan secara urut:

1) Mendownload dan menginstall Guidance Automation Extensions (Release 2007)

Anda cukup menjalankan installer GuidanceAutomationExtensions.msi dan tinggal menekan next , next dan next(seperti instalasi biasa). Tool ini berguna untuk men-generate module, file dan code yang digunakan dalam MVC.

2) Mendownload dan menginstall Guidance Automation Toolkit (Release February 2007)

Tool ini akan berkolaborasi dengan Guidance Automation Extension untuk men-generate source code secara otomatis.

3) Mendownload dan menginstall .NET Framework 3.0 beserta Visual Studio 2005 Extensions for Windows WorkFlow Foundation

Paket ini bersifat opsional sebenarnya karena hanya digunakan untuk mengontrol flow dari suatu page ke page yang lain yang merupakan salah satu fungsi dari controller. Namun saya sarankan untuk menginstallnya agar anda dapat bereksperimen dengan controller yang akan anda buat.

4) Mendownload dan menginstall Web Client Software Factory Documentation (opsional)

Ini merupakan dokumentasi dari WCSF beserta tutorialnya. Saya sangat menganjurkan untuk menginstall dokumentasi ini sebagai panduan anda dan agar anda dapat mempelajari lebih dalam.

5) Mendownload dan menginstall Web Client Software Factory (Release January 2007)

Ini merupakan paket WCSF release 2007. Dari pengalaman saya versi ini cukup stabil. Terdapat bug dalam release ini, namun bukan disebabkan oleh WCSF tetapi oleh Guidance Automation. Namun ini bukan bug yang perlu dirisaukan karena bug ini tidak terkait dengan MVC-nya. Pada artikel selanjutnya saya akan menjelaskan bagaiman mengatasi bug ini.

Jika anda telah mengikuti langkah-langkah diatas makaWCSF sudah dapat dipergunakan untuk development. Tetap setia pada blog ini karena saya akan menjelaskan bagaimana mempergunakan WCSF ini sehingga anda dapat merasakan “The Power of MVC framework’s WCSF”. Selamat mencoba :).

MVC untuk .NET 2.0

Perkenalanku dengan Model View Controller (MVC) pattern dimulai ketika mendevelop aplikasi web menggunakan Java. Meskipun saat itu hanya project simulation, saya dan partner saya Jay, memutuskan untuk menggunakan pattern MVC pada aplikasi web kita. Saat itu kami menggunakan Struts yang digabungkan dengan Spring untuk membentuk MVC framework. Ketika saya mulai dihadapkan project lain yang menggunakan teknologi ASP .NET 2.0, saya mengalami kebingungan untuk mencari framework MVC yang bagus. Konsultasi dengan rekan-rekan senior saya tidak membuahkan hasil. Rata-rata mereka membuat sendiri MVC patternnya. Cukup bagus namun tidak membuat saya puas. Akhirnya saya memutuskan untuk melakukan riset sendiri. Monorail merupakan perkenalan pertamaku. Banyak orang merekomendasikan framework ini karena segi kesederhanaannya. Namun bagiku, ini terlalu sederhana karena banyak konfigurasi yg diperlukan untuk membuat “Your first controller and view”. Saya mengingkan yang lebih simple seperti Struts, namun sepertinya aku terhalang dengan dengan Model View Presenter (MVP) yang merupakan bawaan .NET 2.0. Kemudian saya menemukan Web Client Software Factory (WCSF) yang menggabungkan konsep MVC dan MVP dengan baik. Ini merupakan satu framework yang merupakan satu paket framework yang mengimplementasikan:

  • View-Presenter (VP)
  • Injeksi (Dependency Injection) untuk menginstantiate suatu object.
  • Service Locator untuk service
  • Application controller.

Benar-benar full satu framework MVC-MVP!. Saya tidak perlu menginstall library yg lain untuk melakukan injeksi ke object-object class dan operasi yang melibatkan service. Yang perlu diingat di framework ini adalah terbuat dari kumpulan library yg dikembangkan oleh Microsoft Pattern & Practices. Saya dapat katakan framework ini sudah terbukti dan masih terus dikembangkan oleh kontributornya. Saya jamin anda akan jatuh cinta dengan framework ini semenjak framework ini memiliki dokumentasi yang bagus, bekerja dengan framework .NET 2.0 dengan baik dan memiliki otomatisasi untuk menggenerate project dan source code. Saya rasa framework ini cukup worthed untuk dicoba oleh semua (ASP) .NET 2.0 developer.

Testing

This is a test, created at July 14, 2007

Design a site like this with WordPress.com
Get started