Aralık, 2018 tarihine ait yayınlar gösteriliyor

Data Structure in JavaScript

At a high level, there are basically three types of data structures.  Stacks  and  Queues  are  array-like  structures that differ only in how items are inserted and removed.  Linked Lists ,  Trees ,   and  Graphs  are structures with  nodes  that keep  references  to other nodes.  Hash Tables  depend on  hash functions  to save and locate data. In terms of complexity , Stacks  and  Queues  are the simplest and can be constructed from  Linked Lists .  Trees  and  Graphs  are the most complex because they extend the concept of a linked list.  Hash Tables  need to utilize these data structures to perform reliably.  In terms of efficiency ,  Linked Lists  are most optimal for  recording  and  storing  of data,  while  Hash Tables  are most performant for  searching  and  retrieving  of data. Stack Arguably the most important  Stack  in JavaScript is the  call stack  where we push in the  scope  of a  function  whenever we execute it. Programmatically, it’s jus

OOP in JavaScript

Let's start by looking at how you could define a person with a normal function. Add this function within the  script  element: function createNewPerson ( name ) { var obj = { } ; obj . name = name ; obj . greeting = function ( ) { alert ( 'Hi! I\'m ' + obj . name + '.' ) ; } ; return obj ; } You can now create a new person by calling this function — try the following lines in your browser's JavaScript console: var salva = createNewPerson ( 'Salva' ) ; salva . name ; salva . greeting ( ) ; This works well enough, but it is a bit long-winded; if we know we want to create an object, why do we need to explicitly create a new empty object and return it? Fortunately, JavaScript provides us with a handy shortcut, in the form of constructor functions — let's make one now! Replace your previous function with the following: function Person ( name ) { this . name = name ; this . greeting = function ( ) {