Actually the function is simply returning an object and we are assigning it into a variable and then we use that variable to access all the key value pairs of that object simple -.-
Bro how come atfer using factory function ,document.write(samsung.model) = 'Galaxy' of mobile when i type document.write(mobile.model) it doesn't give me anthing
@@milanpoudel3737 as much i understood about this logic is : you can create multiple object instances and just access your properties. now when ur using constructor object u were creating properties name / key for every object . the problem was key/properties ko code was repeating .so just in factory function u create object instances and u acess properties using it .(no need to write key for every object)
Yes, Ammad is correct. You need to start your left curly braces "{" from same return line. Like " return { " Bottom is the solution: function mobile(model_no) { return { model: model_no, price: function() { return "Price is Rs. 300"; } }; } var lg = mobile("lg 101"); console.log(lg.model + ' and ' + lg.price());
Sir i wrote bellow code but model parameter showing "undefined " i am not getting how to correct it, Please help me. Thanks in advance function config(model, ram, rom) { return { detail: model, ram,rom, price: function() { return " 15000 TK"; } }; } var samsung = config("GalaxyJ7", "2GB", "16GB"); document.write(samsung.model + " " + samsung.ram + " " + samsung.rom + "" );
Factory Function in JavaScript function mobile(){ return { model: "Galaxy", price: function(){ return "Price is Rs.3400"; } }; } var samsung= mobile(); document.write("Price is "+samsung.price()); document.write(" Price is "+samsung.model);
Sir, you have explained all the single topics in detail but you have never explained why we use the anonymous function. may you give me an answer, please?
what if prices are different for different model ?? do write like this add MRP argument/parameter : function mobile(model_no,MRP){ return { model:model_no, price:MRP }; };
//Factory Function with multiple parameters.... function mobile(model_no,type,size,cost){ return { //it is returning the below object model: model_no, make: type, ram: size, price: cost }; } var samsung = mobile('galaxy','S3','4GB',20000); var nokia = mobile('nokia','3310','1GB',10000); var apple = mobile('iphone','10','4GB',70000); console.log(samsung); console.log(nokia); console.log(apple);
I didn't understand a single second of this video. Needed more examples. Also what I see in all youtube tutorials there is no example related to web development. All tutorials are only explaining codes
I am using it from very long time but maze ki bat ye hai mujhe ab pata chala factory function hota kya hai or hum isse kyu use karte hai :-
LOve U Sir g,,,, Aap Ka jawab nahi hai. Unique Teacher in the entire World.
Amazing video 👏👏
sir please explain difference between Object and Object instance?
please explain callback,promise and observable also..it will be very helpful
you nailed it. awesome video.
Jabardast sir jii
owsm sir you are great
I am in London and you are superub
Awesome Bro...
Sir is this like as constructor function. ?
thnaks broo
Just awesome
Actually the function is simply returning an object and we are assigning it into a variable and then we use that variable to access all the key value pairs of that object simple -.-
pro trick : you can watch series at Flixzone. Me and my gf have been using them for watching a lot of movies lately.
@Finn Callan Yea, I've been watching on flixzone for years myself :D
@Finn Callan yea, have been using flixzone for months myself =)
whats the difference between factory function & constructor function??
please reply
Its just two ways of creating function. Nothing else
sir Object instance or Object me kia main difference ha?
Sir ik acha web developer bnny ka lia kia kia seekhna chaheya important languages aur framework suggest ker da please
Mujhy guidence ki zarurat ha
Watch this ruclips.net/video/clsulVp3vHA/видео.html
Bro how come atfer using factory function ,document.write(samsung.model) = 'Galaxy' of mobile when i type document.write(mobile.model) it doesn't give me anthing
same to my code it doesnot work!!
@@story-stacks its not that the code doesn't work but I didn't understand the logic....I mean the javascript logic behind that
@@milanpoudel3737 as much i understood about this logic is : you can create multiple object instances and just access your properties. now when ur using constructor object u were creating properties name / key for every object . the problem was key/properties ko code was repeating .so just in factory function u create object instances and u acess properties using it .(no need to write key for every object)
Sir, it's not working and shows uncaught syntax error in the anonymous function line but still i can't find the error.
Yeah exactly
hello dear i hav an error .. Uncaught SyntaxError: Unexpected token ' : ' in " price : "
function mobile(model_no)
{
return
{
model: model_no,
price : function()
{
return "Price is Rs. 300";
}
};
}
please tell me how to solve
return ka body tag same line se start hoga
function mobile(model_no)
{
return{
model: model_no,
price: function(){return "Price is Rs. 300";}
}
}
Yes, Ammad is correct.
You need to start your left curly braces "{" from same return line. Like " return { "
Bottom is the solution:
function mobile(model_no) {
return {
model: model_no,
price: function() {
return "Price is Rs. 300";
}
};
}
var lg = mobile("lg 101");
console.log(lg.model + ' and ' + lg.price());
quit programming. start pani puri thela
wa sir kya baat hai
sir factory funcation ky ander jo funcation ha is me parameter add kr ky us ko kesy acess kryan gy
thanks
Bhai app kissi ke comment ka Jawab nahi dette ho
sir Nokia ka price kese change hoga?
Sir i wrote bellow code but model parameter showing "undefined " i am not getting how to correct it, Please help me. Thanks in advance
function config(model, ram, rom)
{
return {
detail: model,
ram,rom,
price: function() {
return " 15000 TK";
}
};
}
var samsung = config("GalaxyJ7", "2GB", "16GB");
document.write(samsung.model + " " + samsung.ram + " " + samsung.rom + "" );
Which browser you are using?
you have to write samsung.detail instead of .model.
But bro price change krne ke liye kya karee
how to change mobile price dynamically.
please suggest me.
bro agar nokia 3310 ka price diffrent hua to kaise access krenge
Factory Function in JavaScript
function mobile(){
return {
model: "Galaxy",
price: function(){
return "Price is Rs.3400";
}
};
}
var samsung= mobile();
document.write("Price is "+samsung.price());
document.write(" Price is "+samsung.model);
Sir, you have explained all the single topics in detail but you have never explained why we use the anonymous function. may you give me an answer, please?
Watch Map Method Video
Sir css me transistion kyu nahi kam karta
Same code is not working in chrome.
Any suggestions...
function mobile (a )
{
return {
Model: a,
Price: function ()
{
return "Price = 3000";
}
};
}
var samsung = mobile ( 'Galaxy' );
document.write (samsung.Model + " " + samsung.Price () + "");
var nokia = mobile ( '1200' );
document.write (nokia.Model + " " + nokia.Price () );
This is kinda same as a construction function.
Shouldn't we use construction function instead
what if prices are different for different model ??
do write like this add MRP argument/parameter :
function mobile(model_no,MRP){
return { model:model_no,
price:MRP
};
};
Sir model ka theek hai lekin price same hai
Brother ur videos r good but try to make it in English that would be helpful in interview. I am from south buddy let me learn something from you
*ok*
how can we pass multiple parameters with a factory function
//Factory Function with multiple parameters....
function mobile(model_no,type,size,cost){
return { //it is returning the below object
model: model_no,
make: type,
ram: size,
price: cost
};
}
var samsung = mobile('galaxy','S3','4GB',20000);
var nokia = mobile('nokia','3310','1GB',10000);
var apple = mobile('iphone','10','4GB',70000);
console.log(samsung);
console.log(nokia);
console.log(apple);
I didn't understand a single second of this video. Needed more examples. Also what I see in all youtube tutorials there is no example related to web development. All tutorials are only explaining codes
Sir, it's not working and shows uncaught syntax error in the anonymous function line but still i can't find the error