رفتن به مطلب

مشکل در نوشتن کتابخانه


پست های پیشنهاد شده

سلام دوستان امیدوارم حالتون خوب باشه

من داشتم تمرین میکردم که یه کتابخونه ساده بسازم. بعد به یه مشکلی برخوردم. من دو تا متد نوشتم. تو یکی از اونها، اون یکی رو صدا زدم. ولی کار نمیکنه و مقداری که برمیگردونه undefined هست.

میشه لطفا راهنمایی کنید که مشکلش چی هست. با تشکر فراوان

(function (window) {
    function mathLibrary() {
        this.plusNums = function (x, y) {
            return Number(x) + Number(y);
        };
        this.subNums = function(x , y) {
            this.plusNums(x,-y);
        }
    }
    if(typeof sadra_ml === 'undefined'){
        window.sadra_ml = new mathLibrary();
    }else {
        console.log("There is name conflict");
    }
})(window);

 

لینک به ارسال
  • 2 هفته بعد...

من تست کردم بدون خطا اجرا شد
 

<script type="text/javascript">
(function (window) {
    function mathLibrary() {
        this.plusNums = function (x, y) {
            return Number(x) + Number(y);
        };
        this.subNums = function(x , y) {
            this.plusNums(x,-y);
        }
    }
    if(typeof sadra_ml === 'undefined'){
        window.sadra_ml = new mathLibrary();
    }else {
        console.log("There is name conflict");
    }
})(window);
console.log(window.sadra_ml.plusNums(10,10));
</script>

 

لینک به ارسال
  • 2 هفته بعد...
در در 9/8/2019 at 11:31، Mobin گفته است :

من تست کردم بدون خطا اجرا شد
 


<script type="text/javascript">
(function (window) {
    function mathLibrary() {
        this.plusNums = function (x, y) {
            return Number(x) + Number(y);
        };
        this.subNums = function(x , y) {
            this.plusNums(x,-y);
        }
    }
    if(typeof sadra_ml === 'undefined'){
        window.sadra_ml = new mathLibrary();
    }else {
        console.log("There is name conflict");
    }
})(window);
console.log(window.sadra_ml.plusNums(10,10));
</script>

 

با احترام

من دوباره که نگاهی به کد انداختم فهمیدم که در متد subNums یادم رفته return رو بنویسم و این باعث خطا ( undefined ) شده بود. معذرت میخوام

خیلی ممنون لطف کردید :)

لینک به ارسال

لطفا برای ارسال دیدگاه وارد شوید

شما بعد از اینکه وارد حساب کاربری خود شدید می توانید دیدگاهی ارسال کنید



ورود به حساب کاربری
×
×
  • اضافه کردن...