You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The purpose of static methods is that you can access generic properties on a class without having to create a class instance. Static methods don't have access to the this class instance, and therefore are really only there as utility functions and properties.
For example:
classAudioPlayer{staticdefaultVolume=10;constructor(){this.volume=AudioPlayer.defaultVolume;}}console.log(AudioPlayer.defaultVolume);// 10console.log(AudioPlayer.volume);// property doesn't exist on objectconstPlayer=newAudioPlayer();console.log(Player.volume)// 10
In Pushbar, why we do this is so that we don't have to needlessly bind the class instance to dispatchClose if it isn't utilising any class instance variables.
constpushbar=newPushbar();pushbar.close();// Closes the current active barPushbar.dispatchClose('pushbar-one');// Programatically closes a specific pushbar in your DOM
Hi, pushbar.js is really nice.
A question: what is the advantage of using static methods as opposed to normal methods in things like
static dispatchClose(pushbar)
?The text was updated successfully, but these errors were encountered: