JS Advanced

JS Advanced

by lshettyl

HTML

function Ninja(){ 
  this.swingSword = function(){ 
    return true; 
  }; 
} 
// Should return false, but will be overridden 
Ninja.prototype.swingSword = function(){ 
  return false; 
}; 
 
var ninja = new Ninja();



function Ninja(){ 
  this.swung = true; 
} 
 
var ninjaA = new Ninja(); 
var ninjaB = new Ninja(); 
 
Ninja.prototype.swingSword = function(){ 
  return this.swung; 
};
// will the method be available on previously created objects?


function Ninja(){ 
  this.swung = true; 
} 
 
var ninjaA = new Ninja(); 
var ninjaB = new Ninja(); 
 
Ninja.prototype.swing = function(){ 
  this.swung = false; 
  return this; 
}; 
// What would ninjaA.swing() return?

function katana(){ 
  this.isSharp = true; 
} 
katana(); 
//How do we access isSharp ( === true as it's added to window)