JavaScript private methods

You can do it, but the downside is that it can’t be part of the prototype: function Restaurant() { var myPrivateVar; var private_stuff = function() { // Only visible inside Restaurant() myPrivateVar = “I can set this here!”; } this.use_restroom = function() { // use_restroom is visible to all private_stuff(); } this.buy_food = function() { … Read more

How should I have explained the difference between an Interface and an Abstract class?

I will give you an example first: public interface LoginAuth{ public String encryptPassword(String pass); public void checkDBforUser(); } Suppose you have 3 databases in your application. Then each and every implementation for that database needs to define the above 2 methods: public class DBMySQL implements LoginAuth{ // Needs to implement both methods } public class … Read more

Can we instantiate an abstract class?

Here, i’m creating instance of my class No, you are not creating the instance of your abstract class here. Rather you are creating an instance of an anonymous subclass of your abstract class. And then you are invoking the method on your abstract class reference pointing to subclass object. This behaviour is clearly listed in … Read more

What techniques can be used to define a class in JavaScript, and what are their trade-offs?

Here’s the way to do it without using any external libraries: // Define a class like this function Person(name, gender){ // Add object properties like this this.name = name; this.gender = gender; } // Add methods like this. All Person objects will be able to invoke this Person.prototype.speak = function(){ alert(“Howdy, my name is” + … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)