Posts

Showing posts from January, 2015

Overloaded function in Javascript

Coming from Java background, it is happened to be searched java language constructs while coding javascript. One of such construct is overloaded methods/function. Take a look following code snippet   //Normal sum var intergerSum = sum ( 10 , 20 ); //Expecting item price sum var objectSum = sum ( {item_id: '01' ,name: 'abc' , price: 100 }, {item_id: '02' ,name: 'xyz' , price: 200 } ); As per above code snippet, implementation of ‘sum’ has been abstracted from the user. In the world of type safe language like Java, it is very straight forward, but in case of javascript we need to have our custom implementation. Lets see how can we achieve above in javascript. Lets start with defining a constructor function which introduce a common function to all our custom object so that we can extract integer value for summation. //constructor function to introduce new function to custom object function item (options) { var instance = Object

Do you know Javascript … Try these puzzle

Do you know Javascript … Try these puzzle Javascript is one the most miss-understood language among developers. Everyday I learn new lesson about it.While going through few articles I thought of following JS language puzzles. Handling Array var days = [ 'Monday' , 'Tuesday' , 'Wednesday' , 'Thursday' , 'Friday' , 'Saturday' ]; var length = days. length ; console. log ( 'No of days are ' + days. length ); //Opps we missed Sunday, lets add it days[++ length ] = 'Sunday' ; console. log ( 'Final no of days are ' + days. length ); It is obvious that no of days are 7…. is it ? Written with StackEdit . StackEdit is a full-featured, open-source Markdown editor based on PageDown, the Markdown library used by Stack Overflow and the other Stack Exchange sites. ↩ Here is the text of the footnote . ↩