JavaScript Confused about “hasOwnProperty” for detecting existence of functions

I'm sure this is a duplicate, but I couldn't find the right search terms to find an answer.

I'm trying to use hasOwnProperty() to determine if a function exists on an object or not. I know there are other ways to do this, but I want to understand why that method doesn't work the way I was expecting.

I typed this into a Chrome Dev Tools console:

window.hasOwnProperty("getSelection")
<- true

window.getSelection().hasOwnProperty("empty")
<- false

What I don't understand is why hasOwnProperty("empty") returns false, when that method does exist on the Selection object and I can call it.

window.getSelection().empty()  // Returns no errors
Answer:1

getSelection returns a Selection object instance, which has an internal prototype of Selection.prototype. The prototype has the empty method on it; it's not on the instance itself:

const sel = window.getSelection();
console.log(
  Object.getPrototypeOf(sel) === Selection.prototype,
  Selection.prototype.hasOwnProperty("empty")
);
Answer:2

I'm using the bootstrap-datetimepicker in a form with a radio button, and I'm having a lot of issues with it. The first problem is that only the old version of it is working for me, not the current ...

I'm using the bootstrap-datetimepicker in a form with a radio button, and I'm having a lot of issues with it. The first problem is that only the old version of it is working for me, not the current ...

  1. bootstrap datetimepicker layout
  2. bootstrap datepicker layout

How is it possible to implement, using CSS only (the worst of cases using some JS) to do the following global.css (readonly) .red { color: red; /*tens of lines of additionnal css*/ } ...

How is it possible to implement, using CSS only (the worst of cases using some JS) to do the following global.css (readonly) .red { color: red; /*tens of lines of additionnal css*/ } ...

  1. conditionally apply class angular
  2. conditionally apply class react
  3. conditionally apply class vue
  4. conditionally apply class angular 4
  5. conditionally apply class angularjs
  6. conditionally apply class
  7. conditionally apply class in angular2
  8. conditionally add class react
  9. conditionally add class angular
  10. conditionally add classname react
  11. conditionally add class vue
  12. conditionally add class angular 6
  13. conditionally add class angular 2
  14. conditionally add class angular 4
  15. css conditionally apply class
  16. react conditionally apply classname
  17. vuejs conditionally apply class
  18. conditionally apply css class angular
  19. razor conditionally apply class
  20. add conditionally class

I have a form that is used to update a record, at the bottom I have a submit button. I want it to display a messaging saying "Update Record:" and a Yes and No box. Every way I've found is just for ...

I have a form that is used to update a record, at the bottom I have a submit button. I want it to display a messaging saying "Update Record:" and a Yes and No box. Every way I've found is just for ...

  1. submit button display text
  2. submit button display none
  3. submit button display block
  4. submit button display as link

In the angular tutorial there is this example: <h3> <a [title]="product.name + ' details'"> {{ product.name }} </a> </h3> it works great if I am writing it ...

In the angular tutorial there is this example: <h3> <a [title]="product.name + ' details'"> {{ product.name }} </a> </h3> it works great if I am writing it ...

  1. what difference between bourbon and whiskey
  2. what difference between vegan and vegetarian
  3. what difference between psoriasis and eczema
  4. what difference between flu a and b
  5. what difference between ipad and ipad air
  6. what difference between republic and democracy
  7. what difference between inc and llc
  8. what difference between chromebook and laptop
  9. what difference between md and do
  10. what difference between virus and bacteria
  11. what difference between w2 and w4
  12. what difference between perfume and eau de toilette
  13. what difference between cold and flu
  14. what difference between catholic and christian
  15. what difference between diabetes 1 and 2
  16. what difference between california king and king
  17. what difference between macbook air and pro
  18. what difference between airpod 1 and 2
  19. what difference between medicare and medicaid
  20. what difference between bipolar 1 and 2