1591248752
Understanding CallBacks
Note the argument we take in “cb” which we will understand later is a callback that can be passed. For now we can call this function as
#callbacks-in-python #python #programming
1591118460
A very important piece of data I had to retrieve. Coming from the Future everything back there seemed uncomfortable and convoluted.
#callback #flutter #callback-hell
1595553079
During my journey of learning JavaScript and a few days in with React, I had to come to terms with callback functions. It was impossible to avoid its existence and blindly using it without understanding. To understand callback function we have to know a bit about functions. Here I want to talk about function expression, arrow function, and callback function.
According to MDN doc:
A callback function is a function passed into another function as an argument, which is then invoked inside the outer function to complete some kind of routine or action.
In JavaScript, functions are objects, which means, like any other objects it can be assigned to a variable and passed as an argument to another function. In a nutshell, a callback function is a function that is provided as a parameter for other methods such as forEach method or addEventListener method and gets invoked at a certain point in time.
So how do we do this? Let’s see with an example below:
document.addEventListener(‘click’,whoAmI);
//whoAmI Function Declaration(Function Statement)
function whoAmI(event){
console.log(event.target.tagName)
}
We attached the ‘click’ event listener to document with whoAmI
function as a parameter that logs the tag name of the clicked target. Whenever ‘click’ happens whoAmI
function will be called with an _event_
argument. We call whoAmI
a callback function.
When we call a function by its name followed by ( ), we are telling the function to execute its code. When we name a function or pass a function without the ( ), the function does not execute.** The callback function doesn’t execute right away. Instead, the addEventListener method executes the function when the event occurs.**
One more thing I want to mention is because we used function declaration, we were able to call thewhoAmI
function before it was declared. It’s the magic of hoisting in JS. But with function expression, it doesn’t get hoisted. So the order of writing function expressions and using them as callback would be crucial.
#callback #javascript #callback-function #function #javascript-fundamental
1591248752
Understanding CallBacks
Note the argument we take in “cb” which we will understand later is a callback that can be passed. For now we can call this function as
#callbacks-in-python #python #programming
1652444580
stream-callback
Turns a stream into a callback.
$ npm install stream-callback --save
var rs = new Readable({objectMode: true})
rs.push({foo: 'bar'})
rs.push({foo: 'bar'})
rs.push(null)
streamCb(rs, console.log)
// => { '0': undefined, '1': [ { foo: 'bar' }, { foo: 'bar' } ] }
Required
Type: stream
object
concatOptions
Type: object
eosOptions
Type: object
Required
Type: function
Author: Kikobeats
Source Code: https://github.com/kikobeats/stream-callback
License: MIT license
1624479720
Java is a type-safe programming language. Type safety ensures a layer of validity and robustness in a programming language. It is a key part of Java’s security to ensure that operations done on an object are only performed if the type of the object supports it.
Type safety dramatically reduces the number of programming errors that might occur during runtime, involving all kinds of errors linked to type mismatches. Instead, these types of errors are caught during compile-time which is much better than catching errors during runtime, allowing developers to have less unexpected and unplanned trips to the good old debugger.
Type safety is also interchangeably called strong typing.
Java Generics is a solution designed to reinforce the type safety that Java was designed to have. Generics allow types to be parameterized onto methods and classes and introduces a new layer of abstraction for formal parameters. This will be explained in detail later on.
There are many advantages of using generics in Java. Implementing generics into your code can greatly improve its overall quality by preventing unprecedented runtime errors involving data types and typecasting.
This guide will demonstrate the declaration, implementation, use-cases, and benefits of generics in Java.
#java #guide to understanding generics in java #generics #generics in java #guide to understanding generics in java