const a = {
method1: function(param) {
this.param = param;
$('span[data-count]').text('This is a parameter ' + param);
},
test: 10
}
var b = Object.create(a);
b.method2 = function(param) {
this.param = param;
$('.span2[data-count]').text('This is an another parameter ' + b.param);
}
b.method1('Orange');
b.method2('Blue');
<span data-count></span><br>
<span data-count class="span2"></span>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js">https://stackoverflow.com/questions/ask#</script>
I have an object called a
which is a prototype of an another object called b
. When these are executed, Each results are going to show up different tags span
and .span2
.
My goal is to share the method1's parameter
to method2
without if statement. I would like to assume method1's parameter
on the screen when if method2
has no parameter. So the result would be like;
This is a parameter Orange // method1's result
This is an another parameter Orange // method2's result
If method2
has its own parameter:
This is a parameter Orange // method1's result
This is an another parameter Blue // method2's result
I've tried several ways to get any kinds of clues but no progress at all.
Is there any ways to do this?