So being new to javascript and jQuery I have come across two ways in which a constructor function is defined.
First something like this. Presumably simple javascript constructor function
var assigner = function assigner(object){
this.title = object.title;
this.message = object.message;
this.backGround = object.svgBackground;
this.content = object.content;
this.id = '#' + object.title;
var className = "projects-title";
var tagName = "p";
$(this.id).append("<" + tagName + " class = " + className + "></" + tagName + ">");
var className = "projects-message";
var tagName = "p";
$(this.id).append("<" + tagName + " class = " + className + "></" + tagName + ">");
var className = "projects-background";
var tagName = "p";
$(this.id).append("<" + tagName + " class = " + className + "></" + tagName + ">");
var className = "projects-content";
var tagName = "p";
$(this.id).append("<" + tagName + " class = " + className + "></" + tagName + ">");
$(this.id).find('.projects-title').append(this.title);
$(this.id).find('.projects-message').append(this.message);
$(this.id).find('.projects-background').append(this.backGround);
$(this.id).find('.projects-content').append(this.content);
};
Then Second. Essentially a jQuery constructor function.
(function( $ ){
$.fn.methodToCreate= function(tagName,className,id) {
$(id).append("<"+tagName+" "+"class="+"\'"+className+"\'>"+"SampleContent"+"</"+tagName+">");
return this;
};
})( jQuery );
I was hoping if someone can explain as to why do we require this special syntax in the second function. One thing I have come across quite frequently is people saying it "extends" jQuery. Are there any resources where a newbie can wrap his head around this phenomenon?