D
D
dron1122021-02-15 15:10:40
Vue.js
dron112, 2021-02-15 15:10:40

Why does push() on $router work?

Why does this.$router have a push() method when it's not an array?

This code will output to the console the object we are pushing to when we write this.$router.push('/')

mounted() {
    console.log('this.$router', this.$router);
  },

602a648a7ffed107315744.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
fallus, 2021-02-15
@dron112

This is an object.
And the push method is in its prototype __proto__

A
Anton Anton, 2021-02-15
@Fragster

let a = {push(el) {console.log(el)}}
a.push(1)
also works and aalso not an array.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question