Found 9150 Articles for Object Oriented Programming

What is JavaScript garbage collection?

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:21

341 Views

JavaScript automatically allocates memory, while a variable is declared. Garbage collection finds memory no longer used by the application and releases it since it is of no use. Garbage collector uses algorithms like Mark-and-sweep algorithm, to find the memory no longer used.This algorithm is used to free memory when an object is unreachable. The garbage collector identifies the objects, which are reachable or unreachable. These unreachable objects get the treatment from the automatic garbage collector.The Reference-Counting Garbage Collection is also used for garbage collection in JavaScript. The object will get automatically garbage collected if there are no references to it. ... Read More

How to workaround Objects vs arrays in JavaScript for key/value pairs?

Chandu yadav
Updated on 23-Jun-2020 13:21:48

187 Views

Store it like the following −var players = {    600 : 'Sachin',    300 : 'Brad', };For key/ value pairs, we have used the above solution, since we wanted a one-to-one. We did this to use the key as a lookup key. You can also add more values like this −var players = {    900 : 'Sachin',    300 : 'Brad',    700 : 'Steve',    200 : 'Rahul',    600 : 'Kevin',    500 : 'David', }

How to deal with Internet Explorer and addEventListener problem "Object doesn't support this property or method" in JavaScript?

George John
Updated on 23-Jun-2020 13:05:00

2K+ Views

To deal with “Object doesn’t support this property or method” issue in JavaScript, while using events and Internet Explorer, update your code with this −Example                      ...     You can also use attachEvent in IE to solve this issue like this −if (ev.addEventListener) {    ev.addEventListener('click', myText, false); } else if (ev.attachEvent) {     ev.attachEvent('onclick', myText); }

What is the easiest code for array intersection in JavaScript?

Srinivas Gorla
Updated on 23-Jun-2020 13:03:41

122 Views

For array intersection, you can try to run the following code in JavaScript −Example                    let intersection = function(x, y) {             x = new Set(x), y = new Set(y);             return [...x].filter(k => y.has(k));          };          document.write(intersection([5,7,4,8], [3,9,8,4,3]));          

What's the best way to detect a 'touch screen' device using JavaScript?

Chandu yadav
Updated on 23-Jun-2020 13:08:10

718 Views

The best way to detect a ‘touch screen’ device, is to work around to see whether the touch methods are present within the document model or not.function checkTouchDevice() {    return 'ontouchstart' in document.documentElement; }Here, you can also use it to detect mobile or desktop, like the following −if (checkTouchDevice()) {    // Mobile device } else {    // Desktop }

How to set height equal to the dynamic width (CSS fluid layout) in JavaScript?

Rishi Rathor
Updated on 23-Jun-2020 13:04:18

665 Views

To set height equal to the dynamic width in JavaScript, you can try to run the following code −Example                    .wrap {             width:400px;             height:300px;             border:2px solid yellow;          }          .myChild{             width: 80%;             border:1px solid red;          }                                  var res = $('.myChild').width();          $('.myChild').css({             'height': res + 'px'          });                                        

How do I clear the usage of setInterval()?

George John
Updated on 23-Jun-2020 12:58:39

197 Views

The setInterval() method is used evaluate an expression at specified intervals. This function calls function after every duration milliseconds. This goes for unlimited times. Let’s see an example −It triggers alert(‘Hello’) after every 2000 milliseconds, not only once.setInterval(function() { alert('Hello');}, 2000);To clear the usage of setInterval(), use the window.clearInterval() and set the parameter as the ID, likewindow.setInterval();

Does use of anonymous functions affect performance?

Daniol Thomas
Updated on 23-Jun-2020 12:58:03

340 Views

The usage of anonymous functions affect performance is the sense, you need to create a new function object at each iteration. Anonymous functions are always loaded using a variable name. Anonymous, as the name suggests, allows creating a function without any names identifier. It can be used as an argument to other functions. Call them using a variable name −ExampleThis is how JavaScript anonymous functions can be used −var func = function() {    alert(‘This is anonymous'); } func();Here’s an example −//anonymous function var a = function() {    return 5; }

Is their JavaScript scroll event for iPhone/iPad?

Abhinanda Shri
Updated on 23-Jun-2020 12:57:22

360 Views

Yes, iOS capture onscroll events for a scroll. This is called one-finger events. What the user is tapping or touching decides whether an event is generated or not.Here is panning gesture,Image credit − AppleIt can also be touch and hold gesture,Image credit − Apple

How to set the order of the flexible item, relative to the rest with JavaScript?

Ankitha Reddy
Updated on 30-Jul-2019 22:30:21

123 Views

To set the order of the flexible item, relative to the rest of JavaScript, use the order property. You can try to run the following code to implement order property − Example Live Demo #box { border: 1px solid #000000; width: 420px; height: 150px; display: flex; } #box div { height: 80px; width: 80px; } DIV1 DIV2 DIV3 Set function display() { document.getElementById("myID1").style.order = "3"; document.getElementById("myID2").style.order = "1"; document.getElementById("myID3").style.order = "2"; }

Advertisements