Home > front end >  Js interview questions, sealing function.
Js interview questions, sealing function.

Time:05-15

Does anyone know how this package? My general idea is to create a function, and then do judgment depending on the incoming parameters, return different results, but write found don't know how to write, very embarrassed, not encapsulated

CodePudding user response:

 
The class Player {
The constructor (nodeId, videoId) {
Enclosing nodeId=nodeId
Enclosing videoId=videoId
}

Play () {
The console. The log (' play... ', enclosing nodeId, enclosing videoId)
}

Pause () {
The console. The log (' pause... ', enclosing nodeId, enclosing videoId)
}
}

The class TxPlayer extends Player {
The constructor (options) {
Super (options. ContainerId options. Vid)
}

Play () {
Super. Play ()
}

Pause () {
Super. Pause ()
}
}

The class EgamePlayer extends Player {
The constructor (options) {
Super (options. DomId options. VideoId)
}

Start () {
Super. Play ()
}
Stop () {
Super. Pause ()
}
}

CodePudding user response:

Packaging, for different ginseng, had better to have a middle tier, don't according to different incoming parameters do judgment

If do judgment, subsequent if you add a AQYPlayer again, you need to add parameter judgment, this is not recommended to change business code

CodePudding user response:

refer to the second floor my sensitivity to the fairy response:
packaging, for different ginseng, had better to have a middle tier, don't pass judgment according to different incoming parameters do

If do judgment, subsequent if you add a AQYPlayer again, you need to determine additional parameters, such change business code is not recommended

Thank you, also in the evening watching the js function encapsulation of video, found or not

CodePudding user response:

Got, host demand is encapsulated into a unified foreign calls,

reference 1/f, the sensitivity to the fairy response:
 
The class Player {
The constructor (nodeId, videoId) {
Enclosing nodeId=nodeId
Enclosing videoId=videoId
}

Play () {
The console. The log (' play... ', enclosing nodeId, enclosing videoId)
}

Pause () {
The console. The log (' pause... ', enclosing nodeId, enclosing videoId)
}
}

The class TxPlayer extends Player {
The constructor (options) {
Super (options. ContainerId options. Vid)
}

Play () {
Super. Play ()
}

Pause () {
Super. Pause ()
}
}

The class EgamePlayer extends Player {
The constructor (options) {
Super (options. DomId options. VideoId)
}

Start () {
Super. Play ()
}
Stop () {
Super. Pause ()
}
}

CodePudding user response:

bubble fish _ reference 4 floor response:
got, host demand is encapsulated into a unified foreign calls,

Quote: refer to 1st floor my sensitivity to the fairy reply:
 
The class Player {
The constructor (nodeId, videoId) {
Enclosing nodeId=nodeId
Enclosing videoId=videoId
}

Play () {
The console. The log (' play... ', enclosing nodeId, enclosing videoId)
}

Pause () {
The console. The log (' pause... ', enclosing nodeId, enclosing videoId)
}
}

The class TxPlayer extends Player {
The constructor (options) {
Super (options. ContainerId options. Vid)
}

Play () {
Super. Play ()
}

Pause () {
Super. Pause ()
}
}

The class EgamePlayer extends Player {
The constructor (options) {
Super (options. DomId options. VideoId)
}

Start () {
Super. Play ()
}
Stop () {
Super. Pause ()
}
}

I haven't try effect, but also look on

CodePudding user response:

really wrong and encapsulated into a unified call to use the strategy pattern to encapsulate the

CodePudding user response:

Abstract the player interface, including play and stop two functions,
Wrap two players, exposed two methods, within a method call their implementation,

CodePudding user response:

refer to the eighth floor ziqi0716 response:
abstract the player interface, including play and stop two functions,
Encapsulates two players, exposed two methods, within a method call their implementation,

+ 1, this is the most conventional and maintenance, the implementation of the extension method

Interface declaration:
 
/* *
* @ description ` player interface ` : is there a need to extend the method of continue statement, and the corresponding players in the class implementation can
*/
Interface IPlayer {
/* *
* @ description ` play `
*/
Play () : void
/* *
* @ description ` suspended `
*/
Pause () : void
}


When actual use, the following is not need to write two classes, is a simple statement about to invoke two player (TxPlayer EgamePlayer); I have no the two local goods, to the back is not an error code
 
The class TxPlayer {
The constructor (options: Record) {

}

Play () {}

Pause () {}
}
The class EgamePlayer {
The constructor (options: Record) {

}

Start () {}

Stop () {}
}

CodePudding user response:

TxPlayer player and EgamePlayer player
 

/* *
* @ description ` TxPlayer player `
*/
The class ITxPlayer implements IPlayer {
/* * ` TxPlayer instantiate objects ` */
Private player;
/* *
* the constructor
* @ param {Record nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related