Javascript JQuery Property Scope -
i reading javascript kids nick morgan beginner, , produced following javascript code -
var car = function(x,y) { this.x = x; this.y = y; } car.prototype.draw = function () { var carhtml = '<img src="http://nostarch.com/images/car.png">'; this.carelement = $(carhtml); this.carelement.css({ position:"absolute", left:this.x, top:this.y }); } var tesla = new car (20,20); var nissan = new car (100,200); tesla.draw(); nissan.draw();
now, used javascript constructor method create objects , prototypes
technique create draw method, can call on car objects have created each instance of car
.
from experience in python, methods can access properties of object created instance of class.
my question is, properties accessible methods in object created car constructor?
my question is, properties accessible methods in object created car constructor?
they're accessible code has access object. if method created car
constructor (or else) has access object, yes, properties accessible it. if method created car
constructor doesn't (e.g., it's creating method on different object entirely), method may not have access properties.
note whether method has access object may vary depending on how it's called, if it's accessing object via this
. more: how access correct this
inside callback?
javascript has no private properties, yet. if can access object, can access of true properties.
there proposal, @ stage 3*, add private fields javascript objects created via class
syntax. (it used separate private properties proposal, combined class fields proposal.) private data has had long tortured path date, , while proposal has reached stage 3, still has fair bit of road travel.
Comments
Post a Comment