Giter VIP home page Giter VIP logo

export-modules's Introduction

JavaScript Modül Kavramı

JavaScript kullanırken hazladığımız fonksiyon ve değişkenleri modüller halinde farklı dosyalarda tutabiliriz. Böylece hazırladığımız farklı modülleri dilediğimiz zaman farklı projelerde kullanabiliriz.

Mesela, daire alanını ve çevresini hesapladığımız 2 fonksiyondan oluşan bir circe modülümüz olsun. Bu modül içerisinde iki farklı fonksiyon oluşturuyoruz.

Ekran Görüntüsü

const circleArea = (r) => {
    return 3.14 * ( r * r );
}

const circleCircumference = (r) => {
    return 2 * 3.14 * r;
}

Bu oluşturduğumuz fonksiyonları module.exports yadımı ile dışarı aktarıyoruz. Böylelikle bu dosyaya ulaşabilen diğer dosyalardan bu fonksiyonları çağırabileceğiz. Bunun için index.js dosyası içerisinden bu fonksiyonları çağırıyoruz.

Çağırma işlemi için require yöntemini kullanıyoruz. Bu yöntem ile farklı dosyalarda hazırladığımız ve dışarı aktardığımız metod ve değişkenleri içeri alabiliriz.

const { circleArea, circleCircumference } = require('./circle');

Artık içeri aldığımı bu iki fonksiyonu rahatlıkla kullanabiliriz.

circleArea(5);

export-modules's People

Contributors

selamidemir avatar

Watchers

 avatar

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.