OOP4: A hole in prototype chain

function SuperType(){ this.a = 1; this.b = [2]; } SuperType.prototype.c = 3; SuperType.prototype.d = [4]; function SubType(){} SubType.prototype = new SuperType(); var instance1 = new SubType(); instance1.a = ‘s’; instance1.b.push(‘s’); instance1.c = ‘s’; instance1.d.push(‘s’); var instance2 = new SuperType(); console.log(instance2.a);//1 console.log(instance2.b);//[2] console.log(instance2.c);//3 console.log(instance2.d);//[4,’s’] For base type, this.a or SuperType.prototype.c all work like below: var a… Continue reading OOP4: A hole in prototype chain


OOP3: How new works

Student.prototype = new Person(); var student = new Student(); What’s the difference between above two? Firstly, let’s see what new does. 1.create an object 2.set its _proto_ pointing to Person.prototype. 3.Person.apply(object, arguments) In the first case, Student.prototype points to the object that can use all the methods and properties inherited from Person. While Student is… Continue reading OOP3: How new works


OOP1: What is prototype?

Prototype is a property that will be automatically created once you create a new function. And this property points to an object that contains shared properties and methods. And in this object, a property named constructor will be automatically added and points to the new function which is important for checking object type. Person.prototype.constructor//points to Person… Continue reading OOP1: What is prototype?


When to use link or @import?

DIFFERENCE: Loading Order: 1.Link adds css file first and then compile, while @import will wait until html structure loaded which might influence visual effect. 2.Link parallel downloads css files while @import downloads one by one DOM Supportability: when using DOM changing styles, linked css is OK but imported doesn’t work. Restriction: Link can link JS file… Continue reading When to use link or @import?