Friday, April 6, 2018

Os and Ms

Reading up on stuff is the best way to go. I first learnt about
properties and methods in the context of object oriented programming
with C#. But it applies to html DOM elements (without coding), and in
the context of working with JavaScript ( where one creates methods)  as well.

The difference between a property and a method is clear: both are
with respect to an object, and a method is a function() assigned to
an object as if it were a property. In short then, it is a built-in subroutine in the code.

The capacity to add an EventListener to an element is a method on the
document object. And the ability to do so on an element - as we did yesterday
to turn an input field into a (sort of) button - is an extension of this. If we consult
the list of properties and methods on document, we notice that a number of
these query the document, for example, we can ask it to return a list of the image
elements; or tell us the last time the document was modified.(Both are properties).
Or tell it to create a new element ( a method). We recognize a method because it has
parentheses(), and hence takes inputs from us to do the task.

 These things are useful when dealing with complex sites and large programs.
(I tried asking document what the size of a div was the other day: its changeable,
depending on the screen size one uses. It struck me later this was a dumb-ass request.
Document could tell me width was 450 px if I had put that in the code. If I wanted to
monitor an element size in real time, I would need to create a widget like the  on W3
School TRY IT pages...)

Here's  a mind-bender: in JavaScript, property itself has attributes. Value (changeable)
and enumerable, configurable, and writable. One can query a JS object property on
these matters (instead of hitting one's head against the wall). ECMAScript5 allows one to get and
set these latter attributes...(ECMA defines the standard, JavaScript is an implementation).

https://www.w3schools.com/jsref/dom_obj_document.asp

No comments: