string
stored inside a variable, and make it the var
name (e.g.var ‘this’ = new HappyFace
) for a new instance of a class?
var happy = “ImSoHappy”;
var “ImSoHappy” = new HappyFace();
var
name, it’s just there to point out that it came from the string inside happy
var App = {};
var happy = 'ImSoHappy';
App[happy] = new HappyFace();
you can then even access it like so:
App.ImSoHappy instanceof HappyFace; // true
but the correct way to access a variable that you define like this is:
App[happy]
@SimplyPhy what do you mean by
how would I log the instance then?
simplyphy sends brownie points to @davidjcastner :sparkles: :thumbsup: :sparkles:
:cookie: 354 | @davidjcastner |http://www.freecodecamp.com/davidjcastner
App[happy]
syntax and NOT App.ImSoHappy
. It's clearer how you are defining the variable name, just wanted to point out that you access it like that
App[happy] == App.ImSoHappy
?
App.ImSoHappy
is defined they wouldn't be able to find it
// way one
var HappyFace = function() {};
var App = {
ImSoHappy: new HappyFace()
};
// semantic way to access the variable this way
console.log(App.ImSoHappy instanceof HappyFace); //true
// way two
var App = {};
var happy = 'ImSoHappy';
App[happy] = new HappyFace();
// semantic way to access the variable this way
console.log(App[happy] instanceof HappyFace); //true
object[property]
syntax is because the property name itself is a variable
obj[prop] !== obj.prop
in all situations
prop === defined; // true
, i guess
var HappyFace = function() {};
var App = {};
var happy = 'ImSoHappy.hello';
App[happy] = new HappyFace();
// this explains a case where the obj[prop] !== obj.prop
console.log(App[happy] instanceof HappyFace); //true
console.log(App[happy]); // {}
console.log(App.ImSoHappy.hello); // TypeError: Cannot read property 'hello' of undefined
simplyphy sends brownie points to @davidjcastner :sparkles: :thumbsup: :sparkles:
:warning: simplyphy already gave davidjcastner points
happy=‘foo’; App[happy] = bar;
you would ever try to use App.foo
directly, anyway. That part doesn’t make sense to me. ¯\(ツ)/¯
Given a rectangular matrix of integers and integers n and m, we are looking for the submatrix of size n × m that has the maximal sum among all submatrices of the given size.
Example
For
matrix = [[1, 12, 11, 10],
[4, 3, 2, 9],
[5, 6, 7, 8]]
n = 2 and
m = 1, the output should be
maxSubmatrixSum(matrix, n, m) = 19.