Ana sayfa Genel Javascript – Constructor ve This

Javascript – Constructor ve This


Herkese Merhaba,

Bu yazımda Javascriptte obje oluşturmak için kullanılan yapıcı metodlardan (constructor) ve this anahtar kelimesinden bahsedeceğim.

Öncelikle Javascriptte bir obje oluşturmak için en ilkel yöntem olan Object Literalleri kullanabiliriz.

Ancak bu yöntemle biz her bir objemizin değerini tekrar tekrar başlatmak durumunda kalıyoruz. Eğer biz bu yapıdan yüzlerce obje oluşturmak istersek, çok sayıda kod yazmamız gerekiyor.

Ancak Javascriptte diğer dillerde olduğu gibi constructorlarımızı yazıp bu constructorlara verilen değerler doğrultusunda bir çok obje oluşturabiliriz.

Constructor (Yapıcı Metod)

Constructorların kullanımı oldukça kolaydır. Şimdi örneğimize bakalım.

Burada ne yaptık ? Bir tane constructor oluşturduk ve new anahtar kelimesiyle bu constructor’ı kullanarak 2 tane objemizi oluşturduk.

Peki buradaki this anahtar kelimesinin anlamı nedir ?

this anahtar kelimesi

this anahtar kelimesi üzerinde bulunduğumuz objeyi simgeler ve this.property_name ve this.method_name ifadeleri o anki objemizin özelliklerini ve metodlarını vurgular.

this’in ne anlama geldiğini biraz daha iyi anlamak için isterseniz constructor’ın içinde konsola yazdırmaya çalışalım.

Çıktıya bakacak olursak, this’i konsola yazdırdığımız zaman hangi objenin içindeysek o objenin özellikleri ve metodları,yani en kısa ifadeyle o objenin konsola yazıldığını görebiliriz.

Bir de son olarak Global Scopeta this anahtar kelimesini yazdırdığımız zaman consoleda gördüğümüz objeye bakalım.

Global Scopeta window objesinin içinde olduğumuz için konsola bu objemiz yazılmış oldu. Web sayfalarımızda istersek alert() mesajlarımızı this üzerinden de kullanabiliriz. Çünkü alert() window objesinin bir metodudur.

Bir sonraki yazımızda görüşmek dileğiyle!

Mustafa Murat Coşkun


  1. Fantastic beat ! I would like to apprentice even as you amend your web site, how could i subscribe for a weblog site? The account helped me a acceptable deal. I were a little bit acquainted of this your broadcast offered brilliant transparent idea

  2. I discovered your blog site on google and check a few of your early posts. Continue to keep up the very good operate. I just additional up your RSS feed to my MSN News Reader. Seeking forward to reading more from you later on!…

  3. An impressive share, I just given this onto a colleague who was doing a little analysis on this. And he in fact bought me breakfast because I found it for him.. smile. So let me reword that: Thnx for the treat! But yeah Thnkx for spending the time to discuss this, I feel strongly about it and love reading more on this topic. If possible, as you become expertise, would you mind updating your blog with more details? It is highly helpful for me. Big thumb up for this blog post!

  4. I got this website from my buddy who informed me concerning this website and at the moment this time I am visiting this
    web page and reading very informative articles at this place.

  5. Attractive component of content. I just stumbled upon your site and in accession capital to claim that I get actually loved account your blog posts. Any way I’ll be subscribing in your augment and even I achievement you get right of entry to constantly quickly.

  6. Wonderful website you have here but I was curious about if you knew of any message boards that cover the same topics talked about here? I’d really like to be a part of group where I can get feedback from other knowledgeable people that share the same interest. If you have any recommendations, please let me know. Thanks a lot!

  7. Hello I am so thrilled I found your blog, I really found you by error, while I was researching on Yahoo for something else, Nonetheless I am here now and would just like to say many thanks for a tremendous post and a all round exciting blog (I also love the theme/design), I don’t have time to browse it all at the moment but I have bookmarked it and also added your RSS feeds, so when I have time I will be back to read a great deal more, Please do keep up the superb work.

  8. Thanks for another great article. Where else could anybody get that kind of info in such a perfect way of writing? I’ve a presentation next week, and I’m on the look for such info.

  9. There are some interesting closing dates in this article however I don’t know if I see all of them center to heart. There may be some validity but I will take maintain opinion till I look into it further. Good article , thanks and we would like extra! Added to FeedBurner as nicely

  10. Just want to say your article is as amazing. The clarity for your put up is simply cool and i
    can think you’re a professional in this subject. Fine with your permission let me to grasp your feed to
    stay updated with coming near near post. Thank you one million and please carry on the rewarding

  11. Excellent read, I just passed this onto a friend who was doing a little research on that. And he actually bought me lunch since I found it for him smile So let me rephrase that: Thank you for lunch! “Feeling passionate about something is like getting a peak at your soul smiling back at you.” by Amanda Medinger.

  12. Hello great blog! Does running a blog such as
    this take a large amount of work? I’ve absolutely no understanding of computer programming however I had been hoping to start my own blog in the near future.
    Anyways, should you have any ideas or techniques for new blog owners please
    share. I know this is off subject but I just
    had to ask. Appreciate it!

  13. This design is spectacular! You definitely know how to keep a reader
    amused. Between your wit and your videos, I was almost moved to start my own blog (well, almost…HaHa!) Great job.
    I really loved what you had to say, and more than that, how you presented it.
    Too cool!

  14. F*ckin’ remarkable things here. I’m very glad to see your post. Thanks a lot and i am taking a look forward to touch you. Will you please drop me a mail?

  15. As I web-site possessor I believe the content material here is rattling great , appreciate it for your hard work. You should keep it up forever! Best of luck.

  16. F*ckin’ tremendous things here. I’m very satisfied to peer your post. Thank you so much and i’m having a look ahead to contact you. Will you please drop me a mail?

  17. I carry on listening to the newscast talk about getting boundless online grant applications so I have been looking around for the finest site to get one. Could you advise me please, where could i get some?

  18. Hello! I just would like to give a huge thumbs up for the great info you have here on this post. I will be coming back to your blog for more soon.

  19. I have not checked in here for some time since I thought it was getting boring, but the last few posts are good quality so I guess I will add you back to my daily bloglist. You deserve it my friend 🙂

  20. What¦s Taking place i’m new to this, I stumbled upon this I have discovered It absolutely useful and it has aided me out loads. I’m hoping to contribute & help different customers like its helped me. Good job.

  21. Hi, I think your website might be having browser compatibility issues. When I look at your blog in Ie, it looks fine but when opening in Internet Explorer, it has some overlapping. I just wanted to give you a quick heads up! Other then that, terrific blog!

  22. Nice post. I used to be checking continuously this blog and I’m inspired! Extremely useful info specifically the closing phase 🙂 I take care of such information much. I was seeking this particular info for a very lengthy time. Thank you and best of luck.

  23. The next time I read a blog, I hope that it doesnt disappoint me as much as this one. I mean, I know it was my choice to read, but I actually thought youd have something interesting to say. All I hear is a bunch of whining about something that you could fix if you werent too busy looking for attention.

  24. The very crux of your writing while sounding agreeable originally, did not settle well with me personally after some time. Somewhere throughout the paragraphs you actually were able to make me a believer unfortunately only for a very short while. I nevertheless have a problem with your jumps in assumptions and you would do well to help fill in all those gaps. In the event that you actually can accomplish that, I would certainly be amazed.

  25. Thanks a lot for providing individuals with an extremely nice possiblity to discover important secrets from this web site. It is always very fantastic and packed with a lot of fun for me and my office acquaintances to search your blog at minimum three times in 7 days to read the fresh secrets you have got. Of course, I am also always pleased with your tremendous suggestions served by you. Certain 3 ideas in this posting are undoubtedly the best we’ve ever had.

  26. Its like you read my mind! You seem to know a lot about this, like you wrote the book in it or something. I think that you could do with some pics to drive the message home a bit, but instead of that, this is magnificent blog. A great read. I’ll certainly be back.

  27. I have been surfing on-line greater than three hours today, yet I by no means found any attention-grabbing article like yours. It is lovely price sufficient for me. In my view, if all website owners and bloggers made good content as you did, the net will probably be a lot more helpful than ever before.


Lütfen yorumunuzu giriniz
Buraya isminizi giriniz