- Constructor
// This creates a new empty Object
var newObject = {};
// This creates a new empty Object
var newObject = Object.create(Object.prototype);
var newObject = new Object();
// This creates a new empty Object
var newObject = {};
// This creates a new empty Object
var newObject = Object.create(Object.prototype);
var newObject = new Object();
addEventListener. This is the most common one. Call removeEventListener to clean it up.
setTimeout / setInterval. If you create a recurring timer (e.g. to run every 30 seconds), then you need to clean it up with clearTimeout or clearInterval. (setTimeout can leak if it’s used like setInterval – i.e., scheduling a new setTimeout inside of the setTimeout callback.)
IntersectionObserver, ResizeObserver, MutationObserver, etc. These new-ish APIs are very convenient, but they are also likely to leak. If you create one inside of a component, and it’s attached to a globally-available element, then you need to call disconnect() to clean them up. (Note that DOM nodes which are garbage-collected will have their listeners and observers garbage-collected as well.
const controller = new AbortController(); | |
const { signal } = controller; | |
fetch("http://localhost:8000", { signal }).then(response => { | |
console.log(`Request 1 is complete!`); | |
}).catch(e => { | |
console.warn(`Fetch 1 error: ${e.message}`); | |
}); | |
fetch("http://localhost:8000", { signal }).then(response => { |
const obj = { | |
...condition && { prop: value }, | |
}; |
rm -rf ~/Library/Caches/CocoaPods | |
rm -rf Pods | |
rm -rf ~/Library/Developer/Xcode/DerivedData | |
pod deintegrate | |
pod setup | |
pod install |