html5 - Why would a program allow an object to be initialized when it doesn't support all methods/properties of the interface type it was defined as? -


i'm under impression object must support methods/properties upon being initialized or else program create error. however, if see below defining 2 variables (doc , el) htmldocuments. object assigned these variables must in theory support htmldocument methods/properties, otherwise error raised. in scenario doc control variable , el test variable. "doc" set document object, can support htmldocument interface methods. "el" set single htmlparagraphelement, cannot support htmldocument interface methods. however, no error occurs. in next line, test htmldocument interface method called "createrange" on both variables. works fine (as expected) doc variable. error raised el variable saying "object doesn't support method". expected, don't understand how got far in first place. shouldn't error have been raised when object initialized?

'turn on references microsoft internet controls 'and microsoft html object libraries before running  sub qstn()  dim ie new internetexplorer 'note both doc , el declared within htmldocument interface dim doc htmldocument, el htmldocument  ie.navigate "https://www.youtube.com/"  ie.visible = true  until ie.readystate = 4: loop  'no error expected here.  document object returned 'which has properties , methods of htmldocument interface set doc = ie.document  'why not getting type mismatch here? 'i should not allowed go further on line set el = ie.document.getelementsbytagname("p")(0)  'random method prove actual document object can execute method doc.createrange  'same method used on object declared htmldocument, 'but set htmlparagraphelement.  not working 'because htmlparagraphelement doesn't support el.createrange  end sub 


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -