Today's Question:  What does your personal desk look like?        GIVE A SHOUT

SEARCH KEYWORD -- Function size



  this in JavaScript

this is a keyword in JavaScript. It refers to an internal object created automatically when a function executes, it can only be used in a function. For example:        function test(){     this.x = 1;   }The this keyword will change when a function is called in different situations. However, the general rule is : this refers to the object which calls the function.Next we discuss the use of this in 4 different situatio...

   this,keyword,use,JavaScript     2012-05-05 12:47:37

  Understand this in JavaScript

In JavaScript, this is always pointing to the owner of a function or a method. Function Let's check out function first. function introduce() {      alert("Hello, I am Laruence\r\n"); } For this function, what does this point to? In JavaScript, a global function's owner is the current page, i.e, the window object. Because its a method of the window object if we define a global function. Now you should know the this will point to the window object in the above function. ...

   JavaScript,this,event,call     2013-04-03 04:10:03

  Name resolution order in JavaScript

To understand what value a variable has in JavaScript, we need to understand some concepts such as scope and name resolution order. JavaScript has two scopes; one is program level and the other one is function level. Unlike in C,C++ or Java, JavaScript has no block level scope. So a variable defined in a if block will still be available outside. For example, the below example: var foo = 1; function bar() { if (true) { var foo = 10; } alert(foo); } bar(); The alert will display 10 since the ...

   JavaScript,Scope,Name resolution     2013-07-10 01:29:28

  JavaScript: Private variables

The first thing you often hear when talking about JavaScript is often “JavaScript doesn’t have visibility modifiers, hence it doesn’t support private variables”. This is only valid for 50%, because JavaScript indeed doesn’t have visibility modifiers (public, private, friend) but it has closures and function scopes. With these tools we can make variables private. Let’s take the following function: var names = ["Kenneth", "John", "Marc", "Robert"]; var lookup =...

   JavaScript,private variable,closure     2012-04-28 11:46:34

  JavaScript: Passing by Value or by Reference

In JavaScript, we have functions and we have arguments that we pass into those functions. But how JavaScript handles what you’re passing in is not always clear. When you start getting into object-oriented development, you may find yourself perplexed over why you have access to values sometimes but not other times. When passing in a primitive type variable like a string or a number, the value is passed in by value. This means that any changes to that variable while in the function are com...

   JavaScript,Function,Pass by reference,Pa     2011-07-28 11:05:25

  A Javascript When Function

function when(conditionFunc, execFunc, interval){ if (conditionFunc()){ execFunc(); }else{ setTimeout(function(){ when(conditionFunc, execFunc, interval);}, interval); } } You have some code which should only execute when a condition is true. E.g. You have code which relies on a javascript library but can't be sure the library has loaded yet and don't want the code to execute until it has. This is common if you have a bookmarklet which injects more than one <...

   JavaScript,When,Implementation,When function     2012-02-24 05:08:34

  Understanding Slice Behavior in Go

In Go, understanding how slices behave when passed to functions is crucial for writing efficient and bug-free code. This behavior is often a source of confusion for many developers, especially those new to the language. In this article, we'll explore the difference between passing slices by value and by reference, and how it impacts the modification of slices within functions. Introduction In Go, slices are a fundamental data structure used to work with sequences of elements. They are essentiall...

   PASS BY REFERENCE,ARRAY,SLICE,PASS BY VALUE     2024-03-10 06:43:51

  Introduction to GoLang generics and advanced usage

Generics in Go allow you to write code that can work with multiple types of data, without having to write separate versions of the code for each type. This can make your code more flexible and easier to maintain, as you only need to write and test the code once, rather than maintaining multiple versions. To use generics in Go, you first need to define a type parameter, which is a placeholder for the type that the code will work with. For example, you might define a type parameter called "T" like...

   GOLANG,GENERICS     2022-12-17 05:12:21

  trim() in JavaScript

In the past, JavaScript didn't define the trim() function for String object. This makes web programmers frustrated since they often need to implement this function themselves if they want to handle user inputs. The new version of ECMA-262 introduces the trim() function.15.5.4.20   String.prototype.trim ( )     The following steps are taken:     1.   Call CheckObjectCoercible passing the this value as its argument.   2.   Let S...

   JavaScript,trim(),implementation     2012-07-19 10:58:01

  Should we use Abstract class or Interface?

When we write programs, we may often get into a situation where we don't know whether we should use Abstract class or Interface when we want to define an abstract object. These two are very similar and they are interchangeable in many cases. On Stackoverflow, this question is asked lots of times and it's related to many programming languages. Also in the official documentation of PHP regarding the Abstract class and Interface, people are arguing about this. To understand this question, their dif...

   DIFFERENCE,INTERFACE,ABSTRACT CLASS,COMPARISON,OOP     2013-04-15 11:44:36