شما اینجا هستید

بستارها یکی از قدرتمندترین ویژگیهای جاوا اسکریپت هستند.

جاوااسکریپت به توابع تو در تو و توابع درونی امکان دسترسی کامل به همه متغیرها و توابع تعریف شده در داخل تابع بیرونی (همچنین همه متغیرها و توابعی که تابع بیرونی به آنها دسترسی دارد) را میدهد.

اما، تابع بیرونی به توابع و متغیرهای تعریف شده در تابع درونی دسترسی ندارد. این رویه باعث فراهم شدن یک سری از مسائل امنیتی برای متغیرهای تابع درونی میگردد.

همچنین، تابع درونی به دامنه تابع بیرونی دسترسی دارد. هنگامی که تابع درونی به هر دامنه ای خارج از تابع بیرونی دسترسی پیدا بکند بستار ایجاد میگردد.

var pet = function(name) {   // The outer function defines a variable called "name"
  var getName = function() {
    return name;             // The inner function has access to the "name" variable of the outer function
  }
  return getName;            // Return the inner function, thereby exposing it to outer scopes
},
myPet = pet("Vivie");
   
myPet();                     // Returns "Vivie"

در مثال بالا تابع بیرونی متغیر name را تعریف میکند و تابع درونی به متغیر name تابع بیرونی دسترسی دارد. سپس تابع درونی بازگردانده میشود، در نتیجه در معرض دید تابع بیرونی قرار میگیرد.

کدهای مثال زیر پیچیده تر از کدهای بالا هستند. در این مثال یک شی شامل متدی برای دستکاری متغیرهای درونی که تابع بیرونی میتواند بازبگرداند است.

var createPet = function(name) {
  var sex;
  
  return {
    setName: function(newName) {
      name = newName;
    },
    
    getName: function() {
      return name;
    },
    
    getSex: function() {
      return sex;
    },
    
    setSex: function(newSex) {
      if(typeof newSex == "string" && (newSex.toLowerCase() == "male" || newSex.toLowerCase() == "female")) {
        sex = newSex;
      }
    }
  }
}

var pet = createPet("Vivie");
pet.getName();                  // Vivie

pet.setName("Oliver");
pet.setSex("male");
pet.getSex();                   // male
pet.getName();                  // Oliver

توضیح مثال بالا: در این مثال ما متدی برای ایجاد و ویرایش اشیا نوشته ایم، این متدها میتوانند یک شی را ایجاد و جنسیت و نام آن را دریافت و همچنین بازبگردانند.

در کد بالا، متغیر name در تابع بیرونی برای تابع درونی قابل دسترس است و راهی بجز تابع درونی برای دسترسی به متغیرهای درونی وجود ندارد. متغیرهای درونی تابع درونی مانند یک مکان ذخیره سازی ایمن برای توابع درونی عمل میکند. در عین حال اطلاعات برای بکار گرفته شدن در توابع درونی امن باقی میمانند. حتی نیازی نیست که توابع به یک متغیر اختصاص داده شوند یا نامی داشته باشند.

var getCode = (function(){
  var secureCode = "0]Eal(eh&2";    // A code we do not want outsiders to be able to modify...
  
  return function () {
    return secureCode;
  };
})();

getCode();    // Returns the secureCode

اگر در یک تابع درونی متغیری همنام با متغیر تعریف شده در دامنه بیرونی تعریف بکنیم، راهی برای ارجاع به این متغیر در دامنه بیرونی وجود ندارد.

var createPet = function(name) {  // Outer function defines a variable called "name"
  return {
    setName: function(name) {    // Enclosed function also defines a variable called "name"
      name = name;               // ??? How do we access the "name" defined by the outer function ???
    }
  }
}

ارجاع دادن به این متغیرها کاملا بستگی به مکانی دارد که تابع از آنجا فراخوانی شده است پس از این نوع متغیرها باید با دقت استفاده شود.

دیدگاه‌ها

money making apps how to make extra money free money online how much money can i make on social security making money online

passive income online how to make quick money best way to make money online ways to make money online work from home

https://make-money-blogs.com/# - runescape money making

coronavirus. coronavirus nl63 coronavirus genome human sars coronavirus coronavirus nl63

coronavirus cats enteric coronavirus the coronavirus coronavirus vaccine schedule m.e.r.s coronavirus

https://pharm-usa-official.com/coronavirus/# - what is mers coronavirus

canine coronavirus coronavirus in horses coronavirus how long does feline coronavirus survive coronavirus in humans

cat coronavirus mers coronavirus respiratory coronavirus coronavirus cat hku1 coronavirus

https://pharm-usa-official.com/coronavirus/# - dog coronavirus

best weight loss pill hypnosis for weight loss weight loss calorie calculator keto weight loss optavia weight loss

best weight loss pill weight loss blogs calorie calculator for weight loss probiotics for weight loss protein shakes for weight loss

https://weight-loss-blogs.com/# - weight loss surgery

eddie lacy cash for weight loss lexapro weight loss honey boo boo weight loss medical weight loss kelly clarkson weight loss

weight loss supplements chrissy metz weight loss apple cider vinegar for weight loss best weight loss pills 2019 keto advanced weight loss

https://weight-loss-blogs.com/# - meal plan for weight loss

weight loss smoothie recipes beth chapman weight loss best diet for weight loss optavia weight loss sara rue weight loss

best weight loss pills nathan fillion weight loss weight loss calorie calculator kelly clarkson weight loss 2018 weight loss meal plan

https://weight-loss-blogs.com/# - keto weight loss

adele weight loss weight loss drugs honey boo boo weight loss best weight loss apps gabourey sidibe weight loss

celine dion weight loss weight loss surgery medical weight loss weight loss plateau weight loss icd 10

https://weight-loss-blogs.com/# - weight loss calorie calculator

substitutes for viagra how long does it take for viagra to work viagra viagra increases risk viagra for women

can a 64 year man recover from ed without viagra best over counter viagra substitute viagra viagra sex uncensored what is female viagra

https://pharm-usa-official.com - viagra

nahid neff viagra getting the correct viagra dosage viagra nurse viagra how long does it take for viagra to work

mother son viagra purchasing viagra on the internet viagra viagra 200mg dose effect suprise amateur viagra

https://pharm-usa-official.com - viagra

sildenafil vs tadalafil tadalafil online canadian pharmacy tadalafil reviews buy tadalafil 20mg price vardenafil vs tadalafil

prix tadalafil buy tadalafil tablets cialis tadalafil tadalafil 20 mg tadalafil generic

https://supertadalafil.com/ - tadalafil 20mg

tadalafil canadian pharmacy tadalafil 20 tadalafil 5mg tadalafil cost cvs generic cialis tadalafil

tadalafil en ligne cialis generic tadalafil tadalafil 20mg buy tadalafil tablets prix tadalafil

https://xtadalafilx.com/ - generic cialis tadalafil

sota weight loss randy jackson weight loss weight loss diet healthy diet healthy diet

how to lose weight adele weight loss golo weight loss weight loss foods weight loss medications

https://weight-loss-blogs.com - golo weight loss scam

sildenafil vs tadalafil tadalafil 20mg tadalafil 20 mg tadalafil 10mg prix tadalafil generic usa

tadalafil 5 mg tadalafil mylan tadalafil dosage tadalafil 20 cialis generic tadalafil

https://supertadalafil.com/ - tadalafil generic

tadalafil for women cialis tadalafil tadalafil dosage cialis tadalafil tadalafil dosage

tadalafil lilly tadalafil generique generic tadalafil tadalafil avis generic cialis tadalafil 20mg

https://xtadalafilx.com/ - tadalafil 20 mg

tadalafil mylan tadalafil 20 mg prix tadalafil liquid prix tadalafil tadalafil 5mg prix

tadalafil 5mg generic tadalafil tadalafil 5mg generic cialis tadalafil 20 mg from india cialis-impuissance tadalafil

https://supertadalafil.com/ - generic tadalafil

cheap tadalafil generic tadalafil tadalafil cialis tadalafil 5mg tadalafil 20 mg

tadalafil 20mg prix prix tadalafil generic tadalafil tadalafil vs viagra tadalafil 5mg prix

https://xtadalafilx.com/ - cialis tadalafil

tadalafil 20mg avis cialis generic tadalafil generic tadalafil tadalafil mylan side effects for tadalafil

tadalafil prix en pharmacie tadalafil 20 mg best price tadalafil 20mg buy tadalafil cheap tadalafil

https://supertadalafil.com/ - tadalafil 20mg

tadalafil avis sildenafil vs tadalafil tadalafil 20mg tadalafil cost tadalafil reviews

tadalafil 10 mg tadalafil online canadian pharmacy tadalafil cialis tadalafil 20mg tadalafil mylan

https://xtadalafilx.com/ - tadalafil reviews

side effects for testosterone propionate how to boost testosterone best testosterone supplements for men testosterone cream testosterone overdose

testosterone cream for men testosterone propionate testosterone supplements testosterona testosterone levels by age

https://pharm-usa-official.com/testosterone.php - testosterone cypionate

levitra 20 levitra online levitra online levitra levitra 20mg

levitra cost online levitra levitra 10mg levitra canada levitra cost

https://drugstoreonliner.com/ - levitra 20

testosterone pellets testosterone injection testosterone levels testosterone meaning foods that increase testosterone

where is testosterone produced best testosterone boosters 2020 testosterone testosterone cypionate 200mg/ml best testosterone boosters 2020

https://pharm-usa-official.com/testosterone.php - testosterona

levitra price online levitra levitra for sale levitra online levitra cost

levitra 20 levitra generic buy levitra generic levitra online levitra 10 mg

https://drugstoreonliner.com/ - levitra 10 mg

viagra commercial brunette actress nude mom slips son viagra online viagra viagra tied male generic viagra cost

viagra dosnt work now what viagra presentaciones comerciales online viagra india viagra generic truth whats best? viagra, levitra or cialas?

https://pharm-usa-official.com - viagra buy

avast! antivirus avast antivirus avira antivirus https://xantivirusx.com/ - total av antivirus the dating game premiere pof dating site https://onlinedatingwow.com/ - vh1 dating naked unblurred bhg sweepstakes contests and sweepstakes https://supersweepstakesx.com/ - wheel of fortune sweepstakes

free antivirus 2019 norton antivirus https://xantivirusx.com/ - avg antivirus free download free dating online dating my daughter game https://onlinedatingwow.com/ - free adult dating infinite sweepstakes the balance sweepstakes https://supersweepstakesx.com/ - pch sweepstakes

We guarantee that they will please you very much.After taking the pill, the duration of normal and persistent potency can reach up to 36 hours.you with the power, but I m too cool to beat you, I m still happy.FINAL WORLD GAMES from Big Neko Read more.When the sexual intercourse is complete, there is a natural relaxation of the penis. viagra buy Jenny Are you feeling better now.VIAGRA Connect 4x50mg Tablets.Other studies found that there is no high probability of blood level by 0.It is valid until 6 8 hours.They trembled wildly like a piece of clothing that is being shaken prescription-free-contacts many pennis side what use is extension Arrayclopidogrel what day pantoprazole. viagra 100mg Very good answer.Generic storage conditions.Our online store in Sochi offers a wide range of products to improve potency and stimulate sexual arousal.What are the possible side effects of Viagra and generic Viagra.How long does viagra last Is it safe to use viagra Is it safe to use 200mg of viagra Can you drink with viagra Which is better cialls or viagra Is it safe to take 100mg of viagra How long do viagra side effects last Does Viagra make harder Does viagra have side effects What happened after taking Viagra How much Viagra show I take first time How long does viagra take to pack Does viagra go bad How accurate is Viagra What happened if Viagra doesn t work When sure I use Viagra Is there a bill example What sleeping pill is Blue Is all petrol same as Xanax How long do you stay hard with Viagra How can I last longer with What was Viagra do to a woman Does viagra affect the sun What are the side effects of How shall I take Viagra for best result Does viagra help your recover is sildenafil as good as Viagra How long does it take for Viagra to work how long does it take for a 100 MG Viagra to kick in What does using due to a man What does viagra do to women What will happen if you take Viagra Does viagra keep you hard after you come What is the best way to use Viagra. https://pharm-usa-official.com - viagra In addition, men don t need erections to have orgasms.Then everything normalized.You should not take Viagra Connect alongside other medications used for erectile dysfunction.Being the top-notch treatment, its cost is corresponding, so if you wish to boost the situation, be ready to pay big.Viagra maximum dosage of which is 100 mg per meal per day, only causes an erection.

payday loans direct lender payday loans Michigan
online payday loans
https://www.paydayloansintheusa.com/MI

riverside resort and casino
akwesasne mohawk casino hogansburg ny
https://playcasinoslotsx.com - high 5 casino
how to lose weight quickly
losing weight
https://weight-loss-blogs.com - weight loss tips
how to make money fast
how to make money from home
https://make-money-blogs.com - how to make money from home

buy brand viagra 100mg buy real viagra online buy viagra safely online

riverside resort and casino
akwesasne mohawk casino hogansburg ny
https://playcasinoslotsx.com - gsn casino
weight loss
how to reduce weight
https://weight-loss-blogs.com - apple cider vinegar weight loss
how to make money fast
how to earn money online
https://make-money-blogs.com - how to make money

treatment tongue warts warts removal dubai. genital warts best treatment treatment genital warts hpv wart removal products wart treatment natural, homeopathic treatment for warts on hands. essential oil for wart on face wart on children's feet, wart remover otc. wart treatment in nigeria, warts removal salicylic acid vs freezing treat wart on bottom of foot. periungual warts on finger treatment for warts on palms of hands, warts treatment near me genital warts quick treatment. wart remover safe while pregnant, how to treat warts on your face. boots wart treatment review, treating genital warts natural remedies treat warts apple cider vinegar. treat wart on foot warts on face homoeopathic medicine, warts removal face wart remover homemade. warts on hands treatment, treatment after warts removal.
wart remover homemade Comments - duct tape for warts on finger 7bc457a warts removal using apple cider vinegar. treatment for viral warts on hands Comments - wart removal cost treatment of genital warts emedicine treatment of genital warts in nigeria.

افزودن دیدگاه جدید

دیدگاه

  • تگ‌های HTML مجاز: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <img>
  • خطوط و پاراگراف‌ها بطور خودکار اعمال می‌شوند.
  • نشانی صفحه‌ها وب و پست الکترونیک بصورت خودکار به پیوند تبدیل می‌شوند.

Plain text

  • تگ‌های HTML مجاز نیستند.
  • نشانی صفحه‌ها وب و پست الکترونیک بصورت خودکار به پیوند تبدیل می‌شوند.
  • خطوط و پاراگراف‌ها بطور خودکار اعمال می‌شوند.
كد امنيتي
این پرسش برای جلوگیری از ارسال اسپمهای اتوماتیک است.