Giter Club home page Giter Club logo

js-by-examples's People

Contributors

agriboz avatar bmkmanoj avatar bobagit avatar bradym80 avatar davidojedalopez avatar harishmaddali avatar mallowigi avatar monkeywithacupcake avatar nithinsastry avatar samuelsilvadev avatar smnth90 avatar sparanoid avatar trendsetter37 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

js-by-examples's Issues

Add more examples

I think that would be a great idea to add some example to help who is a noob or to help who have no experience with Javascript.

No longer an hoisting issue

Hi Manoj,

We have to update functions_inside_conditional_blocks.md
New JS engines obaying conditional functional declarations.
Run the code of functions_inside_conditional_blocks.md in console:
output will be:

innerFunc: Inside if
innerFuncExpr: Inside if

Functions inside methods and this variable

Hi there!
Always good to see people wanting to help others! And it's a nice little collection :) .

However, there is a little misinterpretation concerning Functions inside methods and this variable and in this particular case, in a forEach function, there is no need to 'hard bind' any context.

The function in //1 is the callback of a forEach loop function.
A forEach function (Array.prototype.forEach) can take 2 arguments even if the second, the "this" argument, is somewhat less known. See Array.prototype.forEach

The snippet

...
this.myNickNames.forEach(
   function (nickName) {  // 1
    console.log(this.myName +' is also known as '+ nickName);  // 2
   }.bind(this)
);
...

could be replaced with

...
this.myNickNames.forEach(
   function (nickName) { console.log(this.myName +' is also known as '+ nickName); }, 
   this  // 2nd arg
);
...

How that's working? Let's try to build a minimal custom forEach function :

function forEach(array, callback, thisArg) {

  var length = array.length;
  var i = 0;

  for(i; i< length; i++){

    // Here, a forEach function applies the callback to thisArg
    callback.apply(thisArg, [array[i], i, array]);  
  }
}

So, I see a lot of people using var self = this statements when using foreach, map and others arrays manipulation functions, and that's not necessary.

And even better, we have now arrows functions with es2015.
Your snippet could be rewritten like this

...
this.myNickNames.forEach( 
   nickName =>  console.log(this.myName +' is also known as '+ nickName);  // Yeah!
);
...

That's all. Hope it can be useful!
And happy Js coding! ;)

Can I help update the declaration of variables?. A good practice!

Scope

let var const

function hi () { alert("hi") }

hi = function () { alert("hello") }

console.log(hi());  //"hello"

better

const hi = function () { alert("hi") }

hi = function () { alert("hello") }

console.log(hello);  // Uncaught TypeError: invalid assignment to const 'hi'
let obj = {};
obj = "string"; //"string"

better

const obj = {};
obj = "string";  // Uncaught TypeError: invalid assignment to const 'obj'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.