Inheritance in JavaScript

Inheritance in JavaScript

May 17, 2010 21:26 by abhishek.tiwari
You may know it before that we can implement OOPs concepts in Javascript. I am going to demonstrate here one of them "Inheritance in Javascript".
Before going head let me tell  you some facts about javascript

  1. In javascript every function can be used to create an object out of it with "new" operator. 
  2. Javascript objects are hashed and interpreted that means you can add any property to them on runtime. 
  3. Every function (when used as class) is inherited by an inbuilt function(class) called "prototype" of that function. the constructor of your function/class is implemented inside the prototype of your function/class. So whatever properties or methods you add in prototype would be available to all objects of your function/class by default.
  4. When any property/method is accessed from an object, interpreter first tries to find it inside the object itself, if it is not there then it looks into prototype class of that object and keeps on going up in its prototype chain unless it finds it. the super base of any object is prototype of "object" class itself. If it does not find it after crawling upto "object" prototype then it throws error of "undefined" or "not found".
Now let me give you an example how to implement inheritance

function Person()
{
    this.eyes = 2;
    this.legs = 2;
    this.color = "white";
}

Now I want to derive another class Man out of it
to do so you need to write as following

Man.prototype.constructor = Man; //this line will tell that man object will be instantiated from its own prototype
Man.prototype = new Person;  //this line will  hook Person into Man's prototype chain

Please note that you have to write the above two lines before creating Man class

now I am writing a "Man" class

function Man()
{
    this.color = "black";
}

just to explain you how you can add some properties/methods in objects prototype directly, you can refer following example

Person.prototype.legs = 4;
Man.prototype.legs = 2;
Man.prototype.hair = "black";

Ok, now I am going to create an object of Man class

var m = new Man(); //m is an  object of Man

alert(m.color); // the interpreter will look into class Man first and will popup black
alert(Man.prototype.color); // since prototype of Man does not contain color property, it will move up the prototype chain and will look into Person prototype and popup "white"
alert(m.legs); //legs are not defined in object "m", it will look ito prototype of "m" and will pop up 2


I hope you must have understood by now how this whole inheritance is going to work. This is not different than how you find it working in C#/VB.Net or any other language.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Book Review: 'The Professional' by Subroto Bagchi

Book Review: 'The Professional' by Subroto Bagchi

October 2, 2009 20:20 by pradeep.mishra

In his latest book 'The Professional' Mr. Bagchi talks about various attributes of a 'True Professional'. The book comprises of approximate 200 pages and I was able to finish it in 3 sittings. I am not a book worm at all and only enjoy few books only. If a book can hold me for initial half an hour I will for sure finish the book asap. After reading book I thought of writing my personal review and here I am.

Summary: It says top 10 attributes of a professional, in order, are..

 

  •  Integrity
  • Commitment and ownership 
  • Action orientation and goal seeking
  • Continuous learning
  • Professional skills
  • Communication
  • Planning & discipline
  • Work quality
  • Attitude
  • Thought leadership

 

 Accordingly book has been divided into 7 parts. Author himself asks to read the book in the order and not jump between different parts. I, personally, liked the book it is not very great book for all but a great book for a young person at the earlier stages of his/her career and for those, who are ready to step into corporate world. Narration is quite good, especially incidents quotation from author's own life experiences. Readers can easily associate themselves with the book and while reading the book they can start self-contemplation. Earlier two books of Mr Bagchi - 'Go Kiss the World' and 'The High-performance Entrepreneur' were also quite successful. But frankly I have not read those books. If you are not too busy and want to know how close, 'to a professional' you are go and give it a shot it won't take much time to finish the book. Here I will write few points about each part of the book and you can get an idea what's book all about.

 

Part I: Integrity

 Integrity is truly a very important aspect of a professional and I agree with the Author. He cites many examples of people who showed integrity and who did not. I have also experienced that people do not take integrity very seriously. Some of them actual don't understand the term even if you don't please go and read this http://en.wikipedia.org/wiki/Integrity. In the last chapter of this part, I think author has become too ideal though he left the answer to individual organization. In this capitalist word you don't fire a sales person, who has forged travel bills but is about to get a million dollar deal. He may be fired just after deal is closed but not before that. I don't see that happening practically. Let's accept this.

Part II: Self- awareness

 For me this was the best part of the book.  It tells why you should be self aware; know what you can do, what are your limits and acceptance of your limitations. All the chapters in this part are very well knitted with each other and good to read. At least I was able to relate them with my professional life

Part III: Professional Qualities 

This part was typical lecture style which you can find in lots of book like to do list, saying no, longer view etc but one chapter I really liked was 'White Space'. It tells you the concept in a very beautiful way. What is white space? White space is the time we get in between our pre-planned time e.g. time you get while going to work by bus, waiting to meet a client. One more line caught my line i.e. 'Whenever you create something, useful, always think of reuse'

Part IV: Managing Volume

 I again liked this part a lot, especially stories narrated in 'Commitment' & ‘Transparency’ chapter and Manager Employee dialog where manager asks employee why was he late for the office. Again I feel it is important how you tell various concepts to reader. It should be simple; I should be able to associate myself with it. Mr. Bag chi did a beautiful job here.

Part V:  Managing Complexity

 If you, like me, are not aware of incidents, cited in this part it is a very good part otherwise an average section. Specially story about 3 professionals and 9 types of intelligences. I didn't know about these things before.

Part VI: New world imperatives

Here authors talks about gender, governance, IP rights and culture. The best chapter is cross culture sensitivity and gives real insight.

Part VII: The professional's professional

Here author talks about top 10 qualities of an unprofessional and a professional (mentioned at the starting of this review). Nice and concise explanation. 

Finally I would like to quota favorite lines from book

'The day you feel empty shift the attention from yourself to others - go and spend time with a bunch of colleagues who have just joined the organization, help and intern with his work, write series of how-to articles based on your experiences, take a pro-bono work with your industry association. See how pitcher of emptiness begins to fill again'

'..A true professional has a calibrated thermostat which prompts the degree of reaction and control required in any given situation.

Happy reading!!! 

Disclaimer: The opinion expressed here is my independent personal opinion and are not related to either author or publisher of the book Penguin. The quotes mentioned here are directly taken from the book without any permission from author or publisher. In case you want these to be removed please drop me an email at pradeep.mishra /at/  noesispedia dot com. 

 

 


Currently rated 4.0 by 1 people

  • Currently 4/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

SQL Server 2005 Management Studio tips

SQL Server 2005 Management Studio tips

February 14, 2009 01:00 by pradeep.mishra

Tip # 1

Problem:  You have too many connections stored in your management studio using IP address. Sometime it is hard to remember the IP address vs server mapping. Or you have scripts to run on various servers in same management studio instance.

Solution: Use SQL Server Connection Registration feature as shown in diagram below and you can organize all your connections in amazing ways. To get this window just go to View -> Registered Servers.

 

 

Tip # 2

Problem: You are trying to get the things done using SQL Server designer because you don’t remember the query syntax. E.g. Adding a new column, insert script etc

Solution: SQL Server Studio has a feature called Template Explorer(Hit CTRl+Alt+T) and you can see readymade queries available for most of the day to day operation. You can even create your own templates. See the diagram below

 

 

 

Hope this will help you in someway.

kick it on DotNetKicks.com

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

How old are you, and how old were you when you started coding?

How old are you, and how old were you when you started coding?

December 1, 2008 20:06 by pradeep.mishra

There is a very interesting question asked at stackoverflow.com with the subject same as title of this entry '

You can visit the original question here 

I would certainly like to post the live result from stackoverflow here

result1

interesting isn't it?


Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Zip Compressing ASP.NET Session

Zip Compressing ASP.NET Session

December 1, 2008 14:43 by pradeep.mishra

Here are links to a very good articles on how to compress session so that memory on computer may be saved.

Scott Hanselman posted original entry here

A modified useful version was posted by Al Pascual here

Hope this helps!

 

 


Currently rated 3.5 by 2 people

  • Currently 3.5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5