mirror of
https://github.com/Stone-Red-Code/website.git
synced 2026-09-07 16:06:12 +02:00
content: update content titles to match wanted format
This commit is contained in:
@@ -5,6 +5,6 @@ created_at: 2019/07/27
|
|||||||
title: Callbacks
|
title: Callbacks
|
||||||
---
|
---
|
||||||
|
|
||||||
# Callbacks are everywhere
|
## Callbacks are everywhere
|
||||||
|
|
||||||
If you've been doing javascript for any amount of time you'll have noticed that callbacks appear in just about every single piece of code.
|
If you've been doing javascript for any amount of time you'll have noticed that callbacks appear in just about every single piece of code.
|
||||||
|
|||||||
@@ -2,10 +2,9 @@
|
|||||||
authors:
|
authors:
|
||||||
- "veksen#1060"
|
- "veksen#1060"
|
||||||
created_at: "2019/07/27"
|
created_at: "2019/07/27"
|
||||||
|
title: Iterative vs Functional array helpers
|
||||||
---
|
---
|
||||||
|
|
||||||
# Iterative vs Functional array helpers
|
|
||||||
|
|
||||||
-- placeholder --
|
-- placeholder --
|
||||||
|
|
||||||
## find
|
## find
|
||||||
|
|||||||
@@ -9,14 +9,14 @@ recommended_reading:
|
|||||||
- javascript/es6/arrow-functions
|
- javascript/es6/arrow-functions
|
||||||
---
|
---
|
||||||
|
|
||||||
# A Promise to Keep
|
## A Promise to Keep
|
||||||
|
|
||||||
A `Promise` in Javascript represents an action that has already started, but one that will be
|
A `Promise` in Javascript represents an action that has already started, but one that will be
|
||||||
completed at a later time. Much like in real life, when you create a promise, you are expected
|
completed at a later time. Much like in real life, when you create a promise, you are expected
|
||||||
to fulfill that promise. However, sometimes things go wrong where you can no longer fulfill
|
to fulfill that promise. However, sometimes things go wrong where you can no longer fulfill
|
||||||
a promise you made. This is essentially the main idea behind how promises work in javascript.
|
a promise you made. This is essentially the main idea behind how promises work in javascript.
|
||||||
|
|
||||||
## Basics
|
### Basics
|
||||||
|
|
||||||
When you create a Promise or call a function that returns a Promise in Javascript, you're left
|
When you create a Promise or call a function that returns a Promise in Javascript, you're left
|
||||||
with an object that can either resolve into the actual value that you were promised, or it
|
with an object that can either resolve into the actual value that you were promised, or it
|
||||||
@@ -24,7 +24,7 @@ can reject and leave you with an error for why that promise failed.
|
|||||||
|
|
||||||
We can access these values using the `.then` and `.catch` methods on the `Promise` object respectively.
|
We can access these values using the `.then` and `.catch` methods on the `Promise` object respectively.
|
||||||
|
|
||||||
## A Simple Example
|
### A Simple Example
|
||||||
|
|
||||||
First, let's explore a bit of a made-up example. Imagine we have a promise-returning function
|
First, let's explore a bit of a made-up example. Imagine we have a promise-returning function
|
||||||
called `getMembers` that retrieves all the members in a discord server. When we execute this
|
called `getMembers` that retrieves all the members in a discord server. When we execute this
|
||||||
@@ -50,7 +50,7 @@ getMembers("The Programmers Hangout").then(members => {
|
|||||||
|
|
||||||
This way we are able to make sure that we only try to `console.log` when the `getMembers` function has resolved and ready to be used.
|
This way we are able to make sure that we only try to `console.log` when the `getMembers` function has resolved and ready to be used.
|
||||||
|
|
||||||
## Beginner Mistakes
|
### Beginner Mistakes
|
||||||
|
|
||||||
Promises are possibly the #1 most common source of confusion for beginners. In order
|
Promises are possibly the #1 most common source of confusion for beginners. In order
|
||||||
to avoid falling in pitfalls yourself, you have to remember 2 things about Javascript when
|
to avoid falling in pitfalls yourself, you have to remember 2 things about Javascript when
|
||||||
@@ -85,7 +85,7 @@ getWeather("Los Angeles").then(weather => {
|
|||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
## Real World Example
|
### Real World Example
|
||||||
|
|
||||||
Here is a real function that gets character information from the Rick and Morty API.
|
Here is a real function that gets character information from the Rick and Morty API.
|
||||||
You can try it in your browser if you want to test it out.
|
You can try it in your browser if you want to test it out.
|
||||||
|
|||||||
@@ -2,10 +2,9 @@
|
|||||||
authors:
|
authors:
|
||||||
- "Xetera#0001"
|
- "Xetera#0001"
|
||||||
created_at: "2019/07/26"
|
created_at: "2019/07/26"
|
||||||
|
title: Simplifying Promises
|
||||||
---
|
---
|
||||||
|
|
||||||
# Simplifying Promises
|
|
||||||
|
|
||||||
-- placeholder --
|
-- placeholder --
|
||||||
|
|
||||||
The first naive attempt, using new Promise for something that already returns a promise.
|
The first naive attempt, using new Promise for something that already returns a promise.
|
||||||
|
|||||||
@@ -2,10 +2,9 @@
|
|||||||
authors:
|
authors:
|
||||||
- "supergrecko#3434"
|
- "supergrecko#3434"
|
||||||
created_at: "2019/07/27"
|
created_at: "2019/07/27"
|
||||||
|
title: Singletons
|
||||||
---
|
---
|
||||||
|
|
||||||
# Singletons
|
|
||||||
|
|
||||||
A singleton is a class which is only instantiated once during runtime. This is done by keeping a static property containing its instance on the singleton class.
|
A singleton is a class which is only instantiated once during runtime. This is done by keeping a static property containing its instance on the singleton class.
|
||||||
|
|
||||||
There are multiple benefits to using a singleton class
|
There are multiple benefits to using a singleton class
|
||||||
@@ -16,7 +15,7 @@ There are multiple benefits to using a singleton class
|
|||||||
|
|
||||||
By using a singleton instead of a static class we expose a cleaner class to use and we can use regular instance properties instead of static properties.
|
By using a singleton instead of a static class we expose a cleaner class to use and we can use regular instance properties instead of static properties.
|
||||||
|
|
||||||
# Creating a Singleton in PHP
|
## Creating a Singleton in PHP
|
||||||
|
|
||||||
Creating a class which can be used as a singleton is very simple.
|
Creating a class which can be used as a singleton is very simple.
|
||||||
|
|
||||||
@@ -50,7 +49,7 @@ class Singleton
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
# Testing our Singleton
|
## Testing our Singleton
|
||||||
|
|
||||||
To give a little functionality to our freshly baked Singleton we add these three members to the class
|
To give a little functionality to our freshly baked Singleton we add these three members to the class
|
||||||
|
|
||||||
@@ -93,7 +92,7 @@ $first->setWord("Banana");
|
|||||||
var_dump($first->getWord() === $second->getWord()); // bool(true)
|
var_dump($first->getWord() === $second->getWord()); // bool(true)
|
||||||
```
|
```
|
||||||
|
|
||||||
# Further Research
|
## Further Research
|
||||||
|
|
||||||
Here's a couple links which will help you understand Singletons better.
|
Here's a couple links which will help you understand Singletons better.
|
||||||
|
|
||||||
|
|||||||
@@ -2,9 +2,10 @@
|
|||||||
authors:
|
authors:
|
||||||
- "Xetera#0001"
|
- "Xetera#0001"
|
||||||
date: 2019/06/26
|
date: 2019/06/26
|
||||||
|
title: Some Python Article
|
||||||
---
|
---
|
||||||
|
|
||||||
# Python
|
## Python
|
||||||
|
|
||||||
This is a placeholder post
|
This is a placeholder post
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user