Category : prototype

As far as I know, objects are assigned by the reference (they are not copied). Therefore, if changes in an object occur via one link, then they occur via another. let a = { writer: ‘J.K. Rowling’, singer: ‘Beyonce’, politician: ‘A. Merkel’ }; let b = a; delete a.politician; console.log(b); //there’s no politicaian as well ..

Read more

function protoFunc(name) { this.name; this.getName = function () { return this.name; } } Here I create a constructor. Now, this constructor has a prototype property that contains an object on which you define members, i.e. methods and properties, that you want to be inherited. One of those members is the ‘constructor’ property, which points to ..

Read more

function Member(){ this.x=”hello”; }; var test = new Member(); Member.prototype.x = “test”; console.log(test.x); //hello I originally wrote like this for making a constructor expecting its output would be "test". But it didn’t work, the result was "hello". But when I made the constructor to the below one, it worked. function Member(){ Member.x=”hello”; }; I want ..

Read more

I have angular app having multiple exaternal javascript file included from /app/asset/scripts and working fine while calling from tag. I am trying to call Javascript function from angular(.ts) but It throws error. here is the snippet src/app/asser/scripts/viewer.js function MyView(x, y) { //other stuffs this.initView(x, y); <—- error here } MyView.prototype.initView = function(x, y) { console.log("initView"); ..

Read more