Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

You must login to ask question.

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Share & grow the world's knowledge!

We want to connect the people who have knowledge to the people who need it, to bring together people with different perspectives so they can understand each other better, and to empower everyone to share their knowledge.

  1. The difference between Call, Apply and Bind can be explained with below examples, Call: The call() method invokes a function with a given this value and arguments provided one by one var employee1 = { firstName: "John", lastName: "Rodson" }; var employee2 = { firstName: "Jimmy", lastName: "Baily" };Read more

    The difference between Call, Apply and Bind can be explained with below examples,

    Call: The call() method invokes a function with a given this value and arguments provided one by one

    var employee1 = { firstName: "John", lastName: "Rodson" };
    var employee2 = { firstName: "Jimmy", lastName: "Baily" };
    
    function invite(greeting1, greeting2) {
      console.log(
        greeting1 + " " + this.firstName + " " + this.lastName + ", " + greeting2
      );
    }
    
    invite.call(employee1, "Hello", "How are you?"); // Hello John Rodson, How are you?
    invite.call(employee2, "Hello", "How are you?"); // Hello Jimmy Baily, How are you?

    Apply: Invokes the function with a given this value and allows you to pass in arguments as an array

    var employee1 = { firstName: "John", lastName: "Rodson" };
    var employee2 = { firstName: "Jimmy", lastName: "Baily" };
    
    function invite(greeting1, greeting2) {
      console.log(
        greeting1 + " " + this.firstName + " " + this.lastName + ", " + greeting2
      );
    }
    
    invite.apply(employee1, ["Hello", "How are you?"]); // Hello John Rodson, How are you?
    invite.apply(employee2, ["Hello", "How are you?"]); // Hello Jimmy Baily, How are you?

    bind: returns a new function, allowing you to pass any number of arguments

    var employee1 = { firstName: "John", lastName: "Rodson" };
    var employee2 = { firstName: "Jimmy", lastName: "Baily" };
    
    function invite(greeting1, greeting2) {
      console.log(
        greeting1 + " " + this.firstName + " " + this.lastName + ", " + greeting2
      );
    }
    
    var inviteEmployee1 = invite.bind(employee1);
    var inviteEmployee2 = invite.bind(employee2);
    inviteEmployee1("Hello", "How are you?"); // Hello John Rodson, How are you?
    inviteEmployee2("Hello", "How are you?"); // Hello Jimmy Baily, How are you?

    Call and apply are pretty interchangeable. Both execute the current function immediately. You need to decide whether it’s easier to send in an array or a comma separated list of arguments. You can remember by treating Call is for comma (separated list) and Apply is for Array.

    Whereas Bind creates a new function that will have this set to the first parameter passed to bind().

    See less
    • 0
  2. Prototype chaining is used to build new types of objects based on existing ones. It is similar to inheritance in a class based language. The prototype on object instance is available through Object.getPrototypeOf(object) or **proto** property whereas prototype on constructors function is available tRead more

    Prototype chaining is used to build new types of objects based on existing ones. It is similar to inheritance in a class based language.

    The prototype on object instance is available through Object.getPrototypeOf(object) or **proto** property whereas prototype on constructors function is available through Object.prototype.

    Screenshot

    See less
    • 0
  3. There are many ways to create objects in javascript as below Object constructor: The simplest way to create an empty object is using the Object constructor. Currently this approach is not recommended. var object = new Object(); Object's create method: The create method of Object creates a new objectRead more

    There are many ways to create objects in javascript as below

    1. Object constructor:

      The simplest way to create an empty object is using the Object constructor. Currently this approach is not recommended.

      var object = new Object();
    2. Object’s create method:

      The create method of Object creates a new object by passing the prototype object as a parameter

      var object = Object.create(null);
    3. Object literal syntax:

      The object literal syntax (or object initializer), is a comma-separated set of name-value pairs wrapped in curly braces.

      var object = {
           name: "Sudheer"
           age: 34
      };
      
      Object literal property values can be of any data type, including array, function, and nested object.

      Note: This is an easiest way to create an object

    4. Function constructor:

      Create any function and apply the new operator to create object instances,

      function Person(name) {
        this.name = name;
        this.age = 21;
      }
      var object = new Person("Sudheer");
    5. Function constructor with prototype:

      This is similar to function constructor but it uses prototype for their properties and methods,

      function Person() {}
      Person.prototype.name = "Sudheer";
      var object = new Person();

      This is equivalent to an instance created with an object create method with a function prototype and then call that function with an instance and parameters as arguments.

      function func() {};
      
      new func(x, y, z);

      (OR)

      // Create a new instance using function prototype.
      var newInstance = Object.create(func.prototype)
      
      // Call the function
      var result = func.call(newInstance, x, y, z),
      
      // If the result is a non-null object then use it otherwise just use the new instance.
      console.log(result && typeof result === 'object' ? result : newInstance);
    6. ES6 Class syntax:

      ES6 introduces class feature to create the objects

      class Person {
        constructor(name) {
          this.name = name;
        }
      }
      
      var object = new Person("Sudheer");
    7. Singleton pattern:

      A Singleton is an object which can only be instantiated one time. Repeated calls to its constructor return the same instance and this way one can ensure that they don’t accidentally create multiple instances.

      var object = new (function () {
        this.name = "Sudheer";
      })();
    See less
    • 0
  4. It took me about 6 hours to find out why my custom thumbnails were not created after uploading an image. When I looked in the uploads folder on my server, only the original file was added. This error occurs when you have GD library missing. If you are on ubuntu and using php-fpm, then you just instaRead more

    It took me about 6 hours to find out why my custom thumbnails were not created after uploading an image. When I looked in the uploads folder on my server, only the original file was added.

    This error occurs when you have GD library missing.

    If you are on ubuntu and using php-fpm, then you just install php-gd library.

    In my case i ran

    apt-get install php8.0-gd

    Do not forget to restart the php-fpm

     

    See less
    • 0
  5. If you want to delete everything from folder (including subfolders) use this combination of array_map, unlink and glob: array_map( 'unlink', array_filter((array) glob("path/to/temp/*") ) );

    If you want to delete everything from folder (including subfolders) use this combination of array_map, unlink and glob:

    array_map( ‘unlink’, array_filter((array) glob(“path/to/temp/*”) ) );

    See less
    • 0
  6. The friend keyword in C++ allows the programmer to declare friend functions and classes. class frnd{ private: void somefunc(); }; int frndFUNC(int a) {} class A{ friend class frnd; friend int frndFUNC(int a); }; Some important points about friend functions and classes: Declarations of friend functioRead more

    The friend keyword in C++ allows the programmer to declare friend functions and classes.

    class frnd{
    	private:
    		void somefunc();
    };
    
    int frndFUNC(int a) {}
    
    class A{
    	friend class frnd;
    	friend int frndFUNC(int a);
    };
    
    
    

    Some important points about friend functions and classes:

    1. Declarations of friend functions and classes are always made inside the class definition(can be anywhere either in public and private)
    2. Friend functions and classes are declared by the implementor i.e. only the class can define its friend functions and classes, a function or class cannot declare itself a friend of a class
    3. Friend classes can access the data members of the class but not vice versa i.e. Class frnd can access the data members of class A but class A cannot access members of class frnd.
    4. Friend functions are not inherited.
    See less
    • 0
  7. The correct answer is b) Returns a string with HTML response

    The correct answer is b) Returns a string with HTML response

    See less
    • 0

Latest News & Updates

The Stack Tech Latest Articles

PHP: PHP Hypertext Preprocessor

PHP: PHP Hypertext Preprocessor

PHP (Hypertext Preprocessor) is an open-source scripting language used primarily for web development. It is one of the most popular languages used by developers worldwide. What is PHP? PHP is a server-side scripting language used to build dynamic web pages ...

Time Zone Converter in PHP

Time Zone Converter in PHP

On this page, we bring you simple PHP code for a Time zone converter. This code first sets the default time zone to UTC. Then, it defines the input time zone and time, as well as the output time zone. ...

Using the native web share JavaScript API

Using the native web share JavaScript API

Explore the JavaScript API for invoking the native share dialogue. Share like a pro from a web application Sharing button is one of the most used features online today. Every website article should have sharing button. While there are various ...

Explore Our Blog