1.static —>静态变量或静态方法

  1. 静态变量是不能被改变的
  2. 静态方法是不能被重写的
  3. 静态方法直接通过类名调用—>(方便调用)
  4. 静态方法中不能调用非静态的方法
    1. <script>
    2. class Person{
    3. sayAge(){
    4. console.log(18)
    5. }
    6. static sayName(){
    7. this.sayAge()
    8. console.log("hello")
    9. }
    10. }
    11. var p = new Person();
    12. Person.sayName()
    13. </script>
    image.png

2.static-extends

  1. <srcipt>
  2. class person(){
  3. static request(){
  4. console.log("hello world")
  5. }
  6. }
  7. class student extends person{
  8. static getTop250(){
  9. this.request()
  10. }
  11. }
  12. </script>

image.png

2.1例子—请求网易云—华语

HTTP.js

  1. var baseUrl="https://music.aityp.com/";
  2. class HTTP{
  3. static request({url,data}){
  4. return new Promise((resolve,reject)=>{
  5. wx.request({
  6. url:baseUrl+url,
  7. data,
  8. header:{'content-type':'aplication/json'},
  9. method:'GET',
  10. dataType:'json',
  11. responseType:'text',
  12. success:(res)=>{
  13. resolve(res)
  14. },
  15. fail:(err)=>{
  16. reject(err)
  17. }
  18. });
  19. }
  20. module.exports=HTTP;

IndexModel.js

  1. const HTTP=require('./HTTP')
  2. class IndexModel extends HTTP{
  3. static getMusic(){
  4. return this.request({
  5. url:'top/playlist',
  6. data:{
  7. cat:"华语"
  8. }
  9. })
  10. }
  11. }
  12. module.expots=IndexModel;