Share via


C# vs JavaScript Classes (ECMASCRIPT)

ECMASCRIPT is a method of (concept) using JavaScript as Object Oriented designing.  Knowing about this helps you to work on SharePoint Client Object Development, SharePoint Apps Development as well as any web development that involves JavaScript Objects.

There are a few concepts you need to know. Let's compare those using general OOP language (C#) and ECMASCRIPT (C# vs. JavaScript).

Creating a Class

http://lh3.ggpht.com/-Hh23XHvJikM/UPgDEHKOyzI/AAAAAAAABSE/kTjjknmUVd4/image_thumb%25255B15%25255D.png?imgmax=800 http://lh3.ggpht.com/-aji9z-dNrEk/UPgDGyo_r6I/AAAAAAAABSU/BXnnTCQuvlQ/image_thumb%25255B12%25255D.png?imgmax=800

Creating an Object

http://lh6.ggpht.com/-uW3JVKXFL5k/UPgDJ9zi4sI/AAAAAAAABSk/NRlebfr3_PM/image_thumb%25255B21%25255D.png?imgmax=800 http://lh4.ggpht.com/-NeF59-d528Q/UPgDM-4c4rI/AAAAAAAABS0/_QnvbM_vOCY/image_thumb%25255B18%25255D.png?imgmax=800

Public and Private Properties

http://lh4.ggpht.com/-TXCgPHT0FC0/UPlEs9JbHDI/AAAAAAAABTg/epnDe3ou6pk/image_thumb%25255B2%25255D.png?imgmax=800 http://lh5.ggpht.com/-O5IIpcvyH1g/UPlEvhDh9MI/AAAAAAAABTw/L6ZvhmFJDaQ/image_thumb%25255B7%25255D.png?imgmax=800

Method Definition (in best way)

 http://lh5.ggpht.com/-QLENovpTpfY/UPlEyRT-5xI/AAAAAAAABUA/fCQJF511XkA/image_thumb%25255B11%25255D.png?imgmax=800 http://lh6.ggpht.com/-KQvzU3oVFwc/UPlE09k5ppI/AAAAAAAABUQ/XeheyxOMvTc/image_thumb%25255B12%25255D.png?imgmax=800

Note: 

Prototype is something like a template. We are assigning the method save() to the template so it will not recreate everything in the browser memory every time we are creating an object. Assigning the method to the prototype is the best way to do it.)

Inheritance

http://lh5.ggpht.com/-pPEW5_KqjsM/UPlE3g0lybI/AAAAAAAABUg/G1-Vod8RArg/image_thumb%25255B21%25255D.png?imgmax=800 http://lh6.ggpht.com/-c7JniiD5Kuo/UPlE6_Wx8CI/AAAAAAAABUw/Yv7IMJLhqQM/image_thumb%25255B22%25255D.png?imgmax=800