Saturday, September 11, 2021

How objects are created using function constructor?

 lets have an example ,

var Person = function (name, roll, department) {

    this.name = name;

    this.roll = roll;

    this.dept = department;

}

Person.prototype.calculateTotalMarks = function (bangla, english) {

    console.log(bangla + english);

}

var john = new Person("john", 1, "cse");

console.log(john);

john.calculateTotalMarks(50, 50);

var jack = new Person("jack", 2, "eee");

console.log(jack);

jack.calculateTotalMarks(10, 20);

john.calculateTotalMarks(10 , 5);


In the above example Person is the function constructor . Whenever we create our own object john we use new operator which will create an empty object. then function constructor Person will call. We already know in regular function call a new execution context will create and this will point to global object (Window). but by using new operator it will point to our empty object and assign property to our object.

we can declare a method inside function constructor which can be called by the object created using function constructor. But problem is that every object will have a copy of the function . We already know we can inherit method of property inside function prototype.So, we can put method / property in constructor functions property to inherit .

thats why we put that lines,

Person.prototype.calculateTotalMarks = function (bangla, english) {

    console.log(bangla + english);

}

then every object of this constructor function will call that method.

john.calculateTotalMarks(20,30);

Wednesday, September 8, 2021

Inheritance in javascript

 


javascript is a prototype based programming language that means inheritance is possible by using prototype.Every object has this prototype property .

How Inheritance works behind the scene?

Every js object has a prototype property .If any object want to inherit the property /method then these method and property will store in prototype property .Here the person prototype  property is the prototype of john .



By default person constructor's  biggest constructor is object.
In this fig person object can inherit the prototype of object and john can access the property of person prototype and object prototype.

Constructor and instances in javascript

 


Constructor is the blueprint to create object .Here person is the constructor from which we can create objects. jane,mark and john are the 3 instances of person constructor.

Object in javascript

 


Object is use to store data,make code cleaner and structure code.

Tuesday, September 7, 2021

what 3 things need to tell spring ?

 1.what are the bean:-we annotate classes with @Component to specify our bean.

2.What are the dependencies of a bean:-We can annotate with @Autowired to specify dependencies.

3.Where to search for bean:-That means in which package beans are available .

we can specify through @ComponentScan annotation.

In spring boot @SpringBootApplication annotation automatically scan for beans in the package and sub-packages in which package this annotation reside.

--Application context: Application context is the spring container where all the beans are managed .We get beans from application context.

To check what is happening in background-

we can put logger in application.properties file as follows-

looging.level.org.springframework=debug



How events are processed?

 




An event can happen as soon as execution stack is empty. That means all the function have returned.

All the events resides in message queue in browser engine and waiting to be processed.

Since event listener is a function it put on top of execution stack and become the active execution context.

How to access DOM object?

 We can access dom object by querySelector with id in css.

ex:document.querySelector('#score').textContent=100;

 We can access dom object by querySelector with class in css.

ex:document.querySelector('.score').textContent=100;

here ,.score is the class name in css.

if we want to set any html in any html then we use innerHtml.

ex:document.querySelector('.score').textContent='<em>'+100+'</em>';

Javascript module

JavaScript Modules (ES6) let you split code into multiple files and reuse code cleanly. Main keywords: export → make something available...