-
one piece design |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
` private constructor() { // Provide a method for external access, through which this method is used to provide a method for external access to an object public setItem(key: string, value: any) { public getItem(key: string) { /**
|
Beta Was this translation helpful? Give feedback.
`
export default class MyLocalStorage {
// Static properties and object properties are the two major members of a class
static localStorage: MyLocalStorage;
private constructor() {
console.log("This is the constructor of the static method of the singleton design pattern of ts");
}
// Provide a method for external access, through which this method is used to provide a method for external access to an object
// 1. A method with the static keyword is a static method
// 2. Static methods have nothing to do with objects, external object variables cannot call static methods and static properties
// 3. External can be called by class name
// Static methods cannot access instan…